Matching the dollar sign in a regular expression?

Started by cormullion, August 19, 2007, 08:11:13 AM

Previous topic - Next topic

cormullion

Is there some trick to searching for a plain unadorned dollar sign occurring in text with a regular expression? I'm trying to replace the two characters $ when followed by one or two digits with a single character $ followed by the digit(s) found. I've lost sight of the answer in a downpour of baffling backslashes ... :-)

Lutz

#1
like this:



(replace {\$} {abc$cde} "x" 0) => "abcxcde"
(replace "\\\$" "abc\$cde" "x" 0) => "abcxcde"


- both the backslash  and the dollar sign are special characters in regular expression patterns (not the string, only the pattern) and have to be escaped by a



- additionally when using quotes "" than a backslash is also a special character for newLISP. and must be esacped by a .



- the {,} in newLISP takes all chracters literally, makeing things a bit easier.



Lutz

Lutz

#2
... so in my examples I am actually replacing two character: the backslash and a dollar sign with an 'x'.  Nor sure if you meant, the dollar sign only:



(replace {$} {abc$cde} "x" 0) => "abcxcde"
(replace "\$" "abc$cde" "x" 0) => "abcxcde"


Lutz