in reply to Re: Match zero times in regex
in thread Match zero times in regex

The negative look-behind is what the OP was trying to emulate with the {0}. This is definitely the way to go, using negative look-behind and negative look-aheads in the regex! This is a great solution, IMHO...

Just a query: in your regexes, why did you use the m modifier?

Replies are listed 'Best First'.
Re^3: Match zero times in regex
by AnomalousMonk (Archbishop) on Dec 13, 2011 at 04:47 UTC
    ... why did you use the m modifier?

    This is in line with the recommendations of TheDamian's Perl Best Practices (PBP) for regexes. The /m regex modifier causes  ^ $ regex operators also to match after/before embedded newlines. The invariable use of /m and the /s (dot-matches-all, including newlines) modifiers reduces the number of degrees of freedom enjoyed by these operators. In turn, this reduces potential maintenance headaches (I'll show you my scars sometime) and the general brain-hurt associated with regexes.

    The PBP recommendations in general and those for regexes in particular are controversial. (See especially BrowserUk for vigorous counter-argument; also, I think, the JavaFan.) I find many, perhaps most, of the recommendations to have compelling arguments in their favor and I rigorously (dare I say blindly?) use those pertaining to regexes.

      Many thanks for your insights on this... I do have the PBP book and dust it off from time to time to make sure I am not straying from the path. I will make sure to look this recommendation up...