zsh-users
 help / color / mirror / code / Atom feed
From: Roman Neuhauser <neuhauser@sigpipe.cz>
To: Kartik Agaram <ak@akkartik.com>
Cc: zsh-users@zsh.org
Subject: Re: parameter expansion with '$'
Date: Wed, 25 Feb 2015 22:18:56 +0100	[thread overview]
Message-ID: <20150225211856.GD4524@isis.sigpipe.cz> (raw)
In-Reply-To: <CANOtCLVAzdZacxtJps4YEyGGzq5AWfSxXzhQ+TiS-oTOnOMPTw@mail.gmail.com>

# ak@akkartik.com / 2015-02-25 12:50:16 -0800:
> I'd like to only perform the substitution when 'c' occurs at the
> end of the string:
> 
> $ echo ${X/c$/}
> abc  # I'd like this to return 'ab' like above
> 
> I assume others see the same results? Can anybody help me understand why it
> doesn't work, and how I can interpret the '$' as a regular expression
> wildcard rather than some other sort of zsh sigil?

these patterns are *not* regular expressions.  zshexpn(1) says near
the start of PARAMETER EXPANSION:

  In the expansions discussed below that require  a pattern, the  form
  of the pattern is the same as that used for filename generation; see
  the section `Filename Generation'.

  ${name/pattern/repl}
  ${name//pattern/repl}
      [...]

      The pattern may begin with a `#', in which case the pattern must
      match at the start of the string, or `%', in which case it  must
      match  at  the end of the string, or `#%' in which case the pat-
      tern must match the entire string. [...] Note also that the `#',
      `%' and `#%' are  not  active if they occur inside a substituted
      parameter, even at the start.

-- 
roman


  reply	other threads:[~2015-02-25 21:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-25 20:50 Kartik Agaram
2015-02-25 21:18 ` Roman Neuhauser [this message]
2015-02-25 21:20   ` Kartik Agaram

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=20150225211856.GD4524@isis.sigpipe.cz \
    --to=neuhauser@sigpipe.cz \
    --cc=ak@akkartik.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).