Pre: I have my own library, where I work with namespaced modules and classes in Coffescript. this works like in Ruby "namspace::module::class", since '::' is not allowed as class name I replace Module::ClassName
with Module$$ClassName
-> replace(/\$\$/g,'::')
, fine.
Now i struggled doing it reverse: replace(/::/g,'$$')
results in Module$ClassName
having only one Dollar ($)
So i played a around a bit
a="a:a::b:b::c:c"
a.replace(':','$') #-> "a$a::b:b::c:c" clear only first
a.replace(/:/g,'$') #-> "a$a$$b$b$$c$c" better, but wrong we want '::' only
a.replace(/::/g,'$$') #-> "a:a$b:b$c:c" suprise; where is the 2nd Dollar?
a.replace("::",'$$') #-> "a:a$b:b::c:c" try no regexp since dollar has an other meaning? fails only one $
a.replace(/::/g,'\$\$') #-> "a:a$b:b$c:c" ESC the guys? nope
a.replace(/::/g,"\\$\\$") #-> "a:a\$\$b:b\$\$c:c" ESC ESC to get into the deeper?
# and then replace(/\\\$/g,'$') ? overkill
a.replace(/::/g,'$$$') #-> "a:a$$b:b$$c:c" bingo, but why?
# trying more
a.replace(/::/g,'$$$$') #-> "a:a$$b:b$$c:c" 2 get one? one stays alone
a.replace(/::/g,'$$$$$') #-> "a:a$$$b:b$$$c:c" seems so
After all, is logic (and I wonder why I never had the prob before).
So I think (am sure) that '$$' escapes to one '$' because '$n' references to matching groups - but even if there is no regexp in?