[thelist] reg Exp

Carl Meyer cjmeyer at npcc.net
Wed May 12 17:38:21 CDT 2004


hi Mark,

On Wed, 12 May 2004, Mark Joslyn wrote:
> How would you structure a regular expression that would evaluate the
> following string:
> 
> strToUse = "[[myName]]Hello[[myName]]"
> 
> And return only the "Hello".
> 
> I use objRegExp.Pattern = "\[\[myName\]\]\w+\[\[myName\]\]" then use the
> Replace function to strip out the unwanted information. It works but it
> ugly.

Regexes are built to be ugly :-)  Seriously, your regex does exactly what
you want it to do (return any word bracketed by [[myName]]), so it's
correct.  Nothing ugly about that.

There are various generalizations you could make to the regex (e.g. make it
match any double-bracketed terms, not just "myName", etc.), but without
knowing more about your problem set I can't really say which generalizations
would be useful to you.

Carl



More information about the thelist mailing list