Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Regular expression expanding and matching
- X-seq: zsh-users 17433
- From: Mark van Dijk <lists+zsh@xxxxxxxxxxxxxx>
- To: "zsh-users@xxxxxxx" <zsh-users@xxxxxxx>
- Subject: Regular expression expanding and matching
- Date: Sun, 25 Nov 2012 16:45:49 +0100
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
Hello,
I was trying to match a string with a regular expression as follows:
---
#!/usr/local/bin/zsh
zmodload zsh/pcre
somestring="121125"
todaysday="25"
yesterday="24"
set -xv
if [[ $somestring -pcre-match \d{4}${todaysday} ]]; then
echo "somestring matches today"
elif [[ $somestring -pcre-match \d{4}${yesterday} ]]; then
echo "somestring matches yesterday"
fi
set +xv
---
Relevant output:
---
+./zshtest:9> [[ $somestring -pcre-match \d{4}${todaysday} ]]
+./zshtest:11> [[ $somestring -pcre-match \d{4}${yesterday} ]]
---
Apparently there is no expansion of ${todaysday} and ${yesterday}. This
is not really surprising because in regular expressions many characters
have a different meaning.
So what's the proper way to achieve this type of expression matching?
Thank you,
Mark
Messages sorted by:
Reverse Date,
Date,
Thread,
Author