DWQA QuestionsCategory: ServerDoes grep regular matching under Linux not support lazy mode
frogjie asked 2 months ago

My test under Linux (Ubuntu) is shown in the figure below. I wanted to matchAnd < EM >, it turns out that they can’t match lazily
Does grep regular matching under Linux not support lazy mode

My test results under the regular matching online tool are as follows
Does grep regular matching under Linux not support lazy mode
Thank you!

2 Answers
Best Answer
Evian answered 2 months ago

POSIX regular does not support laziness. If your grep supports PCRE (- P option), use it.
The syntax, feature support and implementation of different regular engines are different, and the compatibility is not good. To test regularity, you need to use the tools you actually want to use.

Lin_R answered 2 months ago

-EperhapsegrepAll belong toExtended regularization, the ability is a little bit unsatisfactory, you can try-POfPerl regularization

echo "this is <EM>first<\EM>" | grep -oP '<.*?>'
Lin_R replied 2 months ago

Never said PCRE is Perl regular, maybe you’re right-PDifferent understanding of -P, --perl-regexp
Interpret PATTERN as a Perl regular expression. This is highly experimental and grep -P may warn of unimplemented features.