zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-users@zsh.org
Subject: Re: substitution groups and patterns i replace string (Emacs' \\1 etc.)
Date: Thu, 03 Mar 2016 09:41:40 +0000	[thread overview]
Message-ID: <20160303094140.705eb3bd@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <87k2lk2ws9.fsf@debian.uxu>

On Thu, 3 Mar 2016 02:08:22 +0100
Emanuel Berg <embe8573@student.uu.se> wrote:
> When I do substitution, can I do groups and patterns
> like in Emacs with \\1, \\2 to reference the
> particular matches, and thus construct the replace
> string out of them any way I like?

You do it with $match, and if you need to refer to positions in the
original string, $mbegin and $mend.  See the description of the (#b)
pattern in the zshexpn manual page.

local -a match mbegin mend

if [[ $url = (#b)http://(*) ]]; then
  print $match[1]
fi

Works with other forms of pattern matching.

pws


  reply	other threads:[~2016-03-03  9:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-03  1:08 Emanuel Berg
2016-03-03  9:41 ` Peter Stephenson [this message]
2016-03-06  5:57   ` Emanuel Berg
2016-03-06  7:15     ` Mikael Magnusson
2016-03-08  2:52       ` Bart Schaefer

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=20160303094140.705eb3bd@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.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).