* Pattern engine extension for \< and \> support?
@ 2023-01-27 10:01 Sebastian Gniazdowski
2023-01-27 13:26 ` Stephane Chazelas
2023-01-27 18:48 ` Daniel Shahaf
0 siblings, 2 replies; 3+ messages in thread
From: Sebastian Gniazdowski @ 2023-01-27 10:01 UTC (permalink / raw)
To: Zsh hackers list
[-- Attachment #1: Type: text/plain, Size: 917 bytes --]
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:
\bmyvat\b
I'm not sure if distinction of left and right boundary offered by \<, \>
actually makes a difference.
Zsh has similar sequences already - (#s) and (#e). They do match 0=length
strings on begin or end of the matched string. So maybe the topic is known
to any implementing person? Is it hard to add such \b or \<,\> sequences?
Could it be also possible to make it backward-safe, i.e. the sequence be
ignored by proceeding Zsh versions?
--
Best regards,
Sebastian Gniazdowski
[-- Attachment #2: Type: text/html, Size: 2272 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Pattern engine extension for \< and \> support?
2023-01-27 10:01 Pattern engine extension for \< and \> support? Sebastian Gniazdowski
@ 2023-01-27 13:26 ` Stephane Chazelas
2023-01-27 18:48 ` Daniel Shahaf
1 sibling, 0 replies; 3+ messages in thread
From: Stephane Chazelas @ 2023-01-27 13:26 UTC (permalink / raw)
To: Sebastian Gniazdowski; +Cc: Zsh hackers list
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Pattern engine extension for \< and \> support?
2023-01-27 10:01 Pattern engine extension for \< and \> support? Sebastian Gniazdowski
2023-01-27 13:26 ` Stephane Chazelas
@ 2023-01-27 18:48 ` Daniel Shahaf
1 sibling, 0 replies; 3+ messages in thread
From: Daniel Shahaf @ 2023-01-27 18:48 UTC (permalink / raw)
To: Sebastian Gniazdowski; +Cc: Zsh hackers list
Sebastian Gniazdowski wrote on Fri, Jan 27, 2023 at 10:01:15 +0000:
> 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:
>
> \bmyvat\b
>
> I'm not sure if distinction of left and right boundary offered by \<, \>
> actually makes a difference.
>
> Zsh has similar sequences already - (#s) and (#e). They do match 0=length
> strings on begin or end of the matched string. So maybe the topic is known
> to any implementing person? Is it hard to add such \b or \<,\> sequences?
> Could it be also possible to make it backward-safe, i.e. the sequence be
> ignored by proceeding Zsh versions?
This happens to be covered here:
https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/regexp.md
tl;dr For portability use RE_MATCH_PCRE.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-01-27 18:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-27 10:01 Pattern engine extension for \< and \> support? Sebastian Gniazdowski
2023-01-27 13:26 ` Stephane Chazelas
2023-01-27 18:48 ` Daniel Shahaf
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).