[thelist] regular expressions in homesite or dreamweaver?

Kelly Hallman khallman at wrack.org
Fri Aug 22 20:51:45 CDT 2003


On Fri, 22 Aug 2003, David Kaufman wrote:
> actually you should replace with \1 (not $1).  this is one of the ways
> homesite's regexps are different from "real" regexps :-)

I assume the smiley denotes sarcasm?  \1 and $1 are both common, depending
on the environment. perl, for instance, uses \1 to replace paren matches
in a substitution regex but matched parens are assigned to $1, $2, etc
when a match is made. Regex implementations in most languages use \1, I've
mostly seen $1 in desktop applications that have regex features.

I don't know if one method is accepted as more correct, but I've always
thought \1 was preferred to $1. I would consider perl a good measuring
stick for a 'real' regex engine. In perl I learned it as \1, HOWEVER:

It appears as if you can substitute with $1 in perl also, probably because
it assigns the $1 after the match but before the substitution. If that
assumption is true, then I'd say \1 is preferred as a true regex
substitution in perl since $1 is merely interpolating the value of the
scalar $1, so it'd be the same as substituting any variable available.

-- 
Kelly Hallman
http://wrack.org/




More information about the thelist mailing list