String Replacement Ruby regex -


i need replace string of characters sequence; using gsub method

say,

name = "tom"

and appears in text $(name) need replace $(name) tom.

now, replacing name tom , not $(name) tom. can tell me how gsub like.

don't forget escape things:

string = "my name $(name)"  string.gsub(/\$\(name\)/, "tom") # => name tom 

of course can make more generic:

substs = {   name: "tom" }  string.gsub(/\$\((\w+)\)/) |s|   substs[$1.to_sym] end 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -