Quote:
Originally Posted by MadeInGermany
Quote:
Originally Posted by syg00
Negated char classes are non-greedy by definition. No need for perl or perlre.
|
Not true: by definition the [^<]* expands to the maximum. The trick is to except the < character so it cannot go beyond the < character.
|
Saying "not true" is missing the point -
character classes have no notion of greedy or non-greedy, they are a definition of which characters should be included/excluded.
It is the quantifier which may or not be greedy, and the quantifier doesn't care whether it is acting on a regular character class or negative character class.
The point syg00 was probably trying to make (albeit with poorly chosen words) is that, when viable, using a boundary character inside a negative character class with a greedy quantifier is almost always a better choice than using an overly permissive class with a lazy quantifier - i.e. using
"[^<]*<" is better than using ".*?<" so it makes no sense to suggest the latter as an "improvement" to a working pattern (especially at the expense of clouding the important bit of the post highlighting the potential benefit of using Perl variables over Bash ones).
Of course, the ideal solution to changing markup is generally to use a markup-aware parser, such as Shruggy posted.