in reply to Mnemonic for begin/end chars in regexes

Since nobody has mentioned it yet, you can just use the synonyms of \A for the start and \Z for the end. That's about as intuitive as you can get, I would think. The only difference comes if you use the /m modifier. See perlre for the details.


🦛

Replies are listed 'Best First'.
Re^2: Mnemonic for begin/end chars in regexes
by Smonff (Monk) on May 12, 2023 at 14:17 UTC

    I like this one, but I have to admit I would be afraid it could confuse later readers, assuming it is less common than the ^/$ form?

    🌸

      I'm pretty sure that usage of \A and \Z is less common than usage of ^ and $. But is usage of \A and \Z also less common than confusion of ^ and $? Probably not.

      If you want to keep other folks in their comfort zone, stick to ^ and $ and learn which is which. If you are just using your own regexen day-to-day on the CLI then use whatever makes you more comfortable.


      🦛