Regex Question

mskala at ansuz.sooke.bc.ca mskala at ansuz.sooke.bc.ca
Wed Jul 17 21:58:05 CDT 2002


On Wed, 17 Jul 2002, abez wrote:
> $varname
> ${varname}
> but doesn't find
> $varname{

Balancing parentheses with a regular expression is in general impossible;
in fact that's the subject of about a week's worth of lectures in
third-year computer science.  However, if you're reasonably sure that
"varname" isn't going to contain {}s itself, then you can probably get
away with something like this:

  /\$(\{[a-z]*\})|([a-z]*)/

Feel free to substitute something smarter than [a-z]* to match
varname.  The key is to repeat it, because if you try to match an optional
{, varname, and then an optional }, there's no way to avoid matching
${varname .

-- 
Matthew Skala
mskala at ansuz.sooke.bc.ca                    Embrace and defend.
http://ansuz.sooke.bc.ca/




More information about the Victoria-pm mailing list