zsh-users
 help / color / mirror / code / Atom feed
* Regular expression expanding and matching
@ 2012-11-25 15:45 Mark van Dijk
  2012-11-25 18:30 ` Vin Shelton
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Mark van Dijk @ 2012-11-25 15:45 UTC (permalink / raw)
  To: zsh-users

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-11-25 19:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-25 15:45 Regular expression expanding and matching Mark van Dijk
2012-11-25 18:30 ` Vin Shelton
2012-11-25 19:09   ` Mark van Dijk
2012-11-25 18:57 ` Peter Stephenson
2012-11-25 19:18   ` Vin Shelton
2012-11-25 19:30 ` Bart Schaefer

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).