Created
July 10, 2014 00:29
-
-
Save frank-lsf/6c0f8938f28706b5644d to your computer and use it in GitHub Desktop.
Inconsistent Ruby gsub behavior
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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