From: "Lawrence Velázquez" <larryv@zsh.org>
To: Gamma <GammaFunction@vivaldi.net>, "Lewis Butler" <lbutler@covisp.net>
Cc: zsh-users@zsh.org
Subject: Re: Paramater subsiution
Date: Mon, 28 Jun 2021 01:34:24 -0400 [thread overview]
Message-ID: <3da942af-a0ab-4413-848e-e71c537d4919@www.fastmail.com> (raw)
In-Reply-To: <b135aad4-af98-4f58-8ad7-36a16dbfdbf7@vivaldi.net>
On Sun, Jun 27, 2021, at 6:47 PM, Gamma wrote:
> echo ${i##* - }
>
> Removes the longest prefix ending with ' - '.
${i#* - } would also work and would permit "name" to be completely
arbitrary (assuming that "file 1234" could not possibly contain
" - " as a substring).
https://zsh.sourceforge.io/Doc/Release/Expansion.html#Parameter-Expansion
On Sun, Jun 27, 2021, at 6:40 PM, Lewis Butler wrote:
> I've trued using
>
> ${i:s/file \[0-9\]+ - //}
> ${i:s/file \[0-9\]\[0-9\]\[0-9\]\[0-9\] - //}
> ${i:s/file [0-9]+ - //}
> ${i:s/file [0-9][0-9][0-9][0-9] - //}
> ${i:s/file [^ ]+ - //}
First, you probably wanted ${i/foo/bar} rather than ${i:s/foo/bar}.
The latter matches foo literally unless the HIST_SUBST_PATTERN
option is set. It's also less appropriate in a conceptual sense.
Second, these substitution features use patterns ("globs"), not
regular expressions. Bracket expressions are treated specially
([...], not \[...\]), but '+' generally is not. You can find details
here, including how you could achieve the same effect as '+' (if
you really must):
https://zsh.sourceforge.io/Doc/Release/Expansion.html#Filename-Generation
But you should use Gamma's solution (or my variant), which is simple
and highly portable.
--
vq
next prev parent reply other threads:[~2021-06-28 5:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-27 22:40 Lewis Butler
2021-06-27 22:47 ` Gamma
2021-06-28 5:34 ` Lawrence Velázquez [this message]
2021-06-28 22:33 ` Lewis Butler
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=3da942af-a0ab-4413-848e-e71c537d4919@www.fastmail.com \
--to=larryv@zsh.org \
--cc=GammaFunction@vivaldi.net \
--cc=lbutler@covisp.net \
--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).