CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2010
    Posts
    161

    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

  2. #2
    Join Date
    May 2012
    Location
    Bonn, Germany
    Posts
    43

    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
  •  





Click Here to Expand Forum to Full Width

Featured