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

Re: Possible to match string supporting backslash quoting?



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