in reply to Disambuating $ in (especially /m) regexps

FWIW, there are also \z and \Z available. I agree with anonymonk that some version of \r?\n is better than trying to use $ everywhere.

Replies are listed 'Best First'.
Re^2: Disambuating $ in (especially /m) regexps
by tlhackque (Beadle) on Jan 05, 2016 at 12:49 UTC
    Thanks. I know I can use explicit \n in (\z\Z are end of string, not useful in the middle /m cases). \n is a character; $ is a position assertion true before it. I usually want the position. And by the time one deals with "or end of string", it's a lot of characters in the regex -- but not a lot of clarity. e.g. (?:  )-the-position-[\n\z]? (leaving aside the \r, which $ doesn't handle)

    The doc for /m says Let ^ and $ match next to embedded \n.

    So while TMTOWTDI, I'd still like to understand how $ gets disambiguated, and hopefully some simple rule for keeping it straight.