zsh-workers
 help / color / mirror / code / Atom feed
* regexp-replace and ^
@ 2015-10-29 19:08 Stephane Chazelas
  2015-10-29 23:46 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Stephane Chazelas @ 2015-10-29 19:08 UTC (permalink / raw)
  To: Zsh hackers list

The way regexp-replace works ^ is going to match in several
places:

$ a=aaa zsh -c 'autoload regexp-replace; regexp-replace a "^a" b; echo $a'
bbb

That should probably be documented. (would also affect the \<, \>, \b, and
various look-ahead operators in PCRE).

Or maybe have a (E) for ERE and (P) for PCRE parameter expansion flags for the
${var//pattern/replacement}.

-- 
Stephane


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

* Re: regexp-replace and ^
  2015-10-29 19:08 regexp-replace and ^ Stephane Chazelas
@ 2015-10-29 23:46 ` Bart Schaefer
  2015-10-30 14:27   ` Stephane Chazelas
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2015-10-29 23:46 UTC (permalink / raw)
  To: Zsh hackers list

On Oct 29,  7:08pm, Stephane Chazelas wrote:
}
} Or maybe have a (E) for ERE and (P) for PCRE parameter expansion flags
} for the ${var//pattern/replacement}.

Each of (E) and (P) already means something else.

It ought to be possible to fix regexp-replace.  A leading "^" isn't that
difficult, it just means the loop should only go around once (unless you
expect it to match after embedded newlines).  The tokens that match word
breaks require more thought.  I'm not sure what to make of lookaheads.


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

* Re: regexp-replace and ^
  2015-10-29 23:46 ` Bart Schaefer
@ 2015-10-30 14:27   ` Stephane Chazelas
  0 siblings, 0 replies; 3+ messages in thread
From: Stephane Chazelas @ 2015-10-30 14:27 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh hackers list

2015-10-29 16:46:35 -0700, Bart Schaefer:
> On Oct 29,  7:08pm, Stephane Chazelas wrote:
> }
> } Or maybe have a (E) for ERE and (P) for PCRE parameter expansion flags
> } for the ${var//pattern/replacement}.
> 
> Each of (E) and (P) already means something else.

Indeed. Bummer.

How about some (#E), (#P)? ksh93 has some ~(E:regexp) ~(P:pcre)
and ~(E)regexp, ~(P)pcre.

Probably a lot more complicated.

A pcre_subst builtin addition to the zsh/pcre module would
probably be easy.

Or a zsubst with several options for pattern/ERE/PCRE, case
insensitive...


> It ought to be possible to fix regexp-replace.  A leading "^" isn't that
> difficult, it just means the loop should only go around once (unless you
> expect it to match after embedded newlines).  The tokens that match word
> breaks require more thought.  I'm not sure what to make of lookaheads.

Well, there's also: (foo|^) and variations where you still want
to loop.

-- 
Stephane
> 


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

end of thread, other threads:[~2015-10-30 14:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-29 19:08 regexp-replace and ^ Stephane Chazelas
2015-10-29 23:46 ` Bart Schaefer
2015-10-30 14:27   ` 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).