Dear friends,
I am writing following regex: (http\:\/\/news.*\&\;url\=)
to extract 2 matches from:
<url>http://news.thirdparty.com/intl/en_us/i ... itle>State Department - Hindu</title><link>http://news.thirdparty.com/news/url?sa= ... ubDate>Thu, 09 Oct 2008 03:51:34 GMT</pubDate><a href="http://news.thirdparty.com/news/url?sa= ... xtkMZrEbjA">
But it is giving one match. Please guide me.
Unable to get multiple matches
Moderator: General Moderators
Re: Unable to get multiple matches
Code: Select all
text1.*text2To make it match the shortest match you should use this:
Code: Select all
text1.*?text2There are 10 types of people in this world, those who understand binary and those who don't
Re: Unable to get multiple matches
To make that regex look better, get rid of the needless backslashes. Backslashes are only needed for special regex characters. So you get the more readable regex below:iinf wrote:I am writing following regex: (http\:\/\/news.*\&\;url\=)
Code: Select all
http://news.*?&url=Code: Select all
http://news[^&]*+.*?&url=
Last edited by GeertDD on Fri Oct 10, 2008 6:21 am, edited 1 time in total.
Re: Unable to get multiple matches
// offtopic
@GeertDD - I'm writing an IT game site and one of its sections is RegExps. The idea is to build the fastest regexp according to a specific problem. I just want you to know that some of the problems to solve and their solutions are based on your posts here in this forum
You have an amazing knowledge in regexps. Thanks for sharing it with us
@GeertDD - I'm writing an IT game site and one of its sections is RegExps. The idea is to build the fastest regexp according to a specific problem. I just want you to know that some of the problems to solve and their solutions are based on your posts here in this forum
You have an amazing knowledge in regexps. Thanks for sharing it with us
There are 10 types of people in this world, those who understand binary and those who don't
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Unable to get multiple matches
Geert, I'm assuming you forgot to remove the reluctant dot-star in that regex, I think you meant:GeertDD wrote:...
...Code: Select all
http://news[^&]*+.*?&url=
Code: Select all
http://news[^&]*+&url=Re: Unable to get multiple matches
@VladSun: Thank you for the kind words.
@prometheuzz: No, the .*? part still needs to be there. If you omit it, the regex won't correctly match URLs anymore. More specifically it will fail at the first "&" in the URL, unless that "&" is directly followed by "amp;url=". See?
@prometheuzz: No, the .*? part still needs to be there. If you omit it, the regex won't correctly match URLs anymore. More specifically it will fail at the first "&" in the URL, unless that "&" is directly followed by "amp;url=". See?
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Unable to get multiple matches
Ah, okay, there could be an ampersand before the (sub)string "&" in that url.GeertDD wrote:@VladSun: Thank you for the kind words.
@prometheuzz: No, the .*? part still needs to be there. If you omit it, the regex won't correctly match URLs anymore. More specifically it will fail at the first "&" in the URL, unless that "&" is directly followed by "amp;url=". See?
Thanks.