Actions
Bug #10022
closedInconsistent behavior of gsub replacement
Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
Backport:
Description
In the following code, the two gsub's yield different results. ([[https://gist.github.com/franklsf95/6c0f8938f28706b5644d]])
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}"
My running result is:
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>9999
<key>AppID</key>
<string>000000000000000</string>
--------
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleVersion</key>
<string>0.1.9999</string>
<key>AppID</key>
<string>000000000000000</string>
...which is strangely inconsistent.
Updated by nobu (Nobuyoshi Nakada) almost 10 years ago
- Description updated (diff)
- Status changed from Open to Rejected
The second argument is evaluated before calling gsub
method.
Call it with a block:
puts str.gsub(/(CFBundleVersion<\/key>\n\t.*\.).*(<\/string>)/) {"#{$1}#{ver}#{$2}"}
Actions
Like0
Like0