Mega Code Archive

 
Categories / Ruby / Development
 

Sub and gsub replace with regular expressions

line = "abc" line.sub(/Perl/, 'Ruby')    # replace first 'Perl' with 'Ruby' line.gsub(/Python/, 'Ruby') # replace every 'Python' with 'Ruby'