November 28th, 2012, 03:17 PM
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
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 ?
November 30th, 2012, 02:11 AM
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!
I recently wrote an article about matching numbers with regular expressions.
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!