#466 Wrong match in reg exp using $

closed-invalid
nobody
Program (402)
5
2005-02-17
2005-02-17
Anonymous
No

Having this string in a line:

div(abc, temp(xxx->y; 1234; 9999)

I have tried to match with this RE:

div\(.*?;[^;]+$

IT MATCHES the whole string though it should not!

div\(.*?;[^;]+

properly matches that portion of the string:

div(abc, temp(xxx->y; 1234

Seems as if the $ blocks the minmal matching
extension ? after the *.

Thanks
vnick@freenet.de

Discussion

  • Eddy De Greef

    Eddy De Greef - 2005-02-17
    • status: open --> closed-invalid
     
  • Eddy De Greef

    Eddy De Greef - 2005-02-17

    Logged In: YES
    user_id=73597

    This is not a bug. Your interpretation of non-greedy
    matching is wrong: it is _not_ minimal matching. It will try
    shorter matches first, but it doesn't exclude longer ones.
    When you specify that the match must end with an
    end-of-line, then the regex engine will look for the
    shortest possible match that satisfies this.
    What you probably need, is this:

    div\([^;]*;[^;]+$

    This will not match on your example.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks