zsh-users
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane@chazelas.org>
To: Sebastian Gniazdowski <sgniazdowski@gmail.com>,
	Zsh Users <zsh-users@zsh.org>
Subject: Re: Possible to match string supporting backslash quoting?
Date: Fri, 27 Jan 2023 13:35:35 +0000	[thread overview]
Message-ID: <20230127133535.7dlqxpnx4f4pppp6@chazelas.org> (raw)
In-Reply-To: <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


      reply	other threads:[~2023-01-27 13:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-27 11:47 Sebastian Gniazdowski
2023-01-27 13:30 ` Stephane Chazelas
2023-01-27 13:35   ` Stephane Chazelas [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230127133535.7dlqxpnx4f4pppp6@chazelas.org \
    --to=stephane@chazelas.org \
    --cc=sgniazdowski@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).