Menu

#3454 Regex anomaly

closed-invalid
5
2010-07-29
2010-07-29
Heklaz
No

jEdit version 4.3.2

A regular expression like ^\S+\s*Problem\s*:.*$ which should anchor to start and end of line matches too much.

See attached screen shot. Because it is a repeated pattern, (far) too many matches are found.

The same regex in java matches only lines like (on the same input file):
a) Problem : xxxxxxxxxxxxxxxxx
b) Problem : zzzzzzzzzzzzzzzzzzzzzzz
c) Problem : vvvvvvvvvvvvvvvvvvvvvvvvv
d) Problem : wwwwwwwwwwwwwww

Discussion

  • Heklaz

    Heklaz - 2010-07-29

    Screen shot of jEdit regex and match

     
  • Björn Kautler

    Björn Kautler - 2010-07-29

    I guess what you really want to do is using the following pattern:

    ^[\s&&[^\n]]*Problem\s*:.*$

    The screenshot looks perfectly fine to me. The anchor matches at one linestart, then you match at least one non-whitespace and then an arbitratry amount of whitespace (newline is also a whitespace). If you would enable dot-all mode, you would even get more matched at the end, because then the "." would match newlines also.

     
  • Björn Kautler

    Björn Kautler - 2010-07-29
    • labels: 102668 --> search and replace
    • status: open --> closed-invalid
     

Log in to post a comment.

MongoDB Logo MongoDB