zsh-workers
 help / color / mirror / code / Atom feed
* please consider using PCRE_DOLLAR_ENDONLY (and PCRE_DOTALL) for rematchpcre
@ 2017-11-22 12:25 Stephane Chazelas
  2017-11-22 21:40 ` Stephane Chazelas
  0 siblings, 1 reply; 6+ messages in thread
From: Stephane Chazelas @ 2017-11-22 12:25 UTC (permalink / raw)
  To: Zsh hackers list

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-01-23 13:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-22 12:25 please consider using PCRE_DOLLAR_ENDONLY (and PCRE_DOTALL) for rematchpcre Stephane Chazelas
2017-11-22 21:40 ` Stephane Chazelas
2018-01-20  7:48   ` Bart Schaefer
2018-01-22  5:28     ` Phil Pennock
2018-01-23  6:57       ` Stephane Chazelas
2018-01-23 13:55         ` Stephane Chazelas

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).