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

Regular expression expanding and matching



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