Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

please consider using PCRE_DOLLAR_ENDONLY (and PCRE_DOTALL) for rematchpcre



Hi.

With setopt rematchpcre

[[ $a =~ a$ ]] currently matches on a=$'a\n'

and

[[ $a =~ ^$ ]] matches on a=$'\n'

While [[ $a =~ . ]] does *not* match on a=$'\n'

That can be quite surprising, and means the behaviour is
different from when using ERE (with norematchpcre)

It can be worked around ([[ $a =~ 'a\z' ]], [[ $a =~ '(?s).'
]]), but IMO at least PCRE_DOLLAR_ENDONLY (if not PCRE_DOTALL)
should be the default at least for [[ $string =~ ... ]] as
in shells, $string usually do not include the newline delimiter.

fish has the same issue with its "string" builtin.

ksh93 with [[ $var =~ (?P)pcre ]] does behave as if both
PCRE_DOLLAR_ENDONLY and PCRE_DOTALL were on.

Note that even with $PCRE_DOLLAR_ENDONLY, one can still do
line-based matching with (?m) or match before the trailing
newline character with \Z.

[[ $'a\nb\n' =~ '(?m)a$' ]] and [[ $'a\nb\n' =~ 'b\Z' ]] return
true.

-- 
Stephane



Messages sorted by: Reverse Date, Date, Thread, Author