Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Possible to match string supporting backslash quoting?
- X-seq: zsh-users 28828
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Possible to match string supporting backslash quoting?
- Date: Fri, 27 Jan 2023 13:35:35 +0000
- Archived-at: <https://zsh.org/users/28828>
- In-reply-to: <20230127133003.spbcjjecye6lz5gp@chazelas.org>
- 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> <20230127133003.spbcjjecye6lz5gp@chazelas.org>
2023-01-27 13:30:03 +0000, Stephane Chazelas:
[...]
> to match a quoted
> string while handling backslash escaping, in ERE, you do:
>
> "(\\.|[^\\"])*"
>
> Whose zsh -o extendedglob equivalent would be:
>
> "(\\?|[^\\"])#"
[...]
For instance, to requote the double-quoted strings with single
quotes:
~$ text='"quoted\\" not "quoted\"quoted" not'
~$ pattern='"(\\?|[^\\"])#"'
~$ print -r -- ${text//(#m)$~pattern/${(qq)${(Q)MATCH}}}
'quoted\' not 'quoted"quoted' not
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author