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

Re: parameter expansion with '$'



# ak@xxxxxxxxxxxx / 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



Messages sorted by: Reverse Date, Date, Thread, Author