Skip to content

Instantly share code, notes, and snippets.

@franklsf95
Created July 10, 2014 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save franklsf95/6c0f8938f28706b5644d to your computer and use it in GitHub Desktop.
Save franklsf95/6c0f8938f28706b5644d to your computer and use it in GitHub Desktop.
Inconsistent Ruby gsub behavior
# In the following code, the two gsub's have different outcomes.
ver = 9999
str = "\t<key>CFBundleDevelopmentRegion</key>\n\t<string>en</string>\n\t<key>CFBundleVersion</key>\n\t<string>0.1.190</string>\n\t<key>AppID</key>\n\t<string>000000000000000</string>"
puts str.gsub /(CFBundleVersion<\/key>\n\t.*\.).*(<\/string>)/, "#{$1}#{ver}#{$2}"
puts '--------'
puts str.gsub /(CFBundleVersion<\/key>\n\t.*\.).*(<\/string>)/, "#{$1}#{ver}#{$2}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment