Skip to content

Difference in multi-line match/pattern between ugrep and ripgrep/pcregrep/pcre2grep? #391

Closed Answered by genivia-inc
AndydeCleyre asked this question in Q&A
Discussion options

You must be logged in to vote

The anchor ^ is part of the initial parenthesized repetition, which causes some ambiguity so take it outside:

$ ugrep '^([^\n]+\n)*[^\n]*'1337'[^\n]*(\n[^\n]+)*' sample.forth
6 7 * .        \ 42 ok
1360 23 - .    \ 1337 ok
12 12 / .      \ 1 ok
13 2 mod .     \ 1 ok

Why is this? Please note that ugrep's default pattern matching is POSIX, which puts some restrictions on regex and anchors because of the internal matching machinery used. I may be able to work around the ^ anchor placement issue in a future update, but I'm not 100% sure.

Simpler is to write this regex with a dot . instead of [^\n] (because dot doesn't match newlines unless explicitly forced to do so with --dotall) so this loo…

Replies: 7 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by AndydeCleyre
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants