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

Re: Possible to match string supporting backslash quoting?



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