Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Possible to match string supporting backslash quoting?
- X-seq: zsh-users 28827
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Possible to match string supporting backslash quoting?
- Date: Fri, 27 Jan 2023 13:30:03 +0000
- Archived-at: <https://zsh.org/users/28827>
- In-reply-to: <CAKc7PVBYyE=m2eyRue7T25_+8WKEu2RB4VRikAidiq=jxnmFEw@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- Mail-followup-to: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- References: <CAKc7PVBYyE=m2eyRue7T25_+8WKEu2RB4VRikAidiq=jxnmFEw@mail.gmail.com>
2023-01-27 11:47:14 +0000, Sebastian Gniazdowski:
> HI,
> I'm matching var="…" and would want to support quoting, i.e.:
> var="abc\"ef". So far I have:
>
> qstr='(#B)(["](#b)(*~(*[^\\]([\\][\\])#["]*)))["]'
> [[ '"qqq--\\"abc"' == (#b)$~qstr ]];printf ·ec=%s\\n $?;@str-dump match
> Output:
> ·ec=1
>
> qstr='(#B)(["](#b)(*~(*[^\\]([\\][\\])#["]*)))["]'
> [[ '"qqq--\"abc"' == (#b)$~qstr ]];printf ·ec=%s\\n $?;@str-dump match
>
> Output:
> ·ec=0
> 1: qqq--\"abc
> 2:
> 3:
>
> So it at least detects a \\" in the input. Would it be possible to utilize
> the negations ~ and ^ to somehow match "str\"ef" as: str"ef, and "str\\"ef"
> as: str?
[...]
I didn't try to decipher your patterns, but to match a quoted
strings while handling backslash escaping, in ERE, you do:
"(\\.|[^\\"])*"
Whose zsh -o extendedglob equivalent would be:
"(\\?|[^\\"])#"
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author