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

Re: Pattern engine extension for \< and \> support?



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