Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Pattern engine extension for \< and \> support?
- X-seq: zsh-workers 51334
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: Pattern engine extension for \< and \> support?
- Date: Fri, 27 Jan 2023 13:26:04 +0000
- Archived-at: <https://zsh.org/workers/51334>
- In-reply-to: <CAKc7PVCAf0roQXYK-_1HD4OGcPVPzd+474=T=5EKMV3uXDTZ-Q@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- Mail-followup-to: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>, Zsh hackers list <zsh-workers@xxxxxxx>
- References: <CAKc7PVCAf0roQXYK-_1HD4OGcPVPzd+474=T=5EKMV3uXDTZ-Q@mail.gmail.com>
2023-01-27 10:01:15 +0000, Sebastian Gniazdowski:
> Hi,
> in regexps, there are \<, \> and also \b sequences, that match zero-length
> string on the word boundary. They are particularly useful for e.g.:
> refactoring substitutions, like e.g.: with sed:
>
> sed -r -i -e 's/\<myvar\>/other/'
>
> This automatically protects pre/suffixed strings like str_myvar and
> myvar_str. In mcedit, I often use \b that's available there (\< and \> do
> not work), to obtain the same effect with the regex:
[...]
Some regexp engines like on BSDs also have [[:<:]] / [[:>:]] for
that which would possibly be easy to add to zsh (I'd think
anything using backslash would be a no-no).
zsh has [[:WORD:]] already as similar to \w. Its [[:<:]],
[[:>:]] would need to honour $WORDCHARS as well for consistency.
\< / \> come from ex/vi in the 70s AFAIK, \b from perl in the 80s.
Perl also has \B and:
\b{} Match at Unicode boundary of specified type
\B{} Match where corresponding \b{} doesn't match
\b Match a \w\W or \W\w boundary
\B Match except at a \w\W or \W\w boundary
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author