-
November 28th, 2012, 04:17 PM
#1
simple regex not working in java
I don't know what I'm doing wrong but I have a problem wit this simple regex which works fine when I test it on rad software regular expression but doesn't work in java
I am trying to get some links that have the following format
<a href="/test/354544/">first line..
<a href="/test/3432423/">second line
<a href="/test/343243/">first line...
<a href="/test/34234/">first line...
now if I apply the following regex
<a href="(/test/.+?/)"> it works
but if i use it in java with the appropriate escaping it doesn't work
<a href=\"(/title/.+?/)\">
I am trying to get the code after the slash(the sigits after the word 'test') which works on rad but when used in jave it works as well but it sort of goes greedy
Can someone tell me what I am doing wrong ?
Thank you
-
November 30th, 2012, 03:11 AM
#2
Re: simple regex not working in java
Try replacing the dot by \d, since you only want digits.
Otherwise the dot will be matched greedily and it will eat all your other <a hrefs!
PS:
I recently wrote an article about matching numbers with regular expressions.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|