From: Stephane Chazelas <stephane@chazelas.org>
To: Sebastian Gniazdowski <sgniazdowski@gmail.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Pattern engine extension for \< and \> support?
Date: Fri, 27 Jan 2023 13:26:04 +0000 [thread overview]
Message-ID: <20230127132604.h5ouknlasoqdginh@chazelas.org> (raw)
In-Reply-To: <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
next prev parent reply other threads:[~2023-01-27 13:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-27 10:01 Sebastian Gniazdowski
2023-01-27 13:26 ` Stephane Chazelas [this message]
2023-01-27 18:48 ` Daniel Shahaf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230127132604.h5ouknlasoqdginh@chazelas.org \
--to=stephane@chazelas.org \
--cc=sgniazdowski@gmail.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).