开发者

Ruby doesn't recognize the g flag for regex

开发者 https://www.devze.com 2022-12-20 11:22 出处:网络
Is it implied by default in str开发者_开发百科.scan? Is it off by default in str[regex] ?Yes, how often the regex is applied depends on the method used, not on the regex\'s flags.

Is it implied by default in str开发者_开发百科.scan? Is it off by default in str[regex] ?


Yes, how often the regex is applied depends on the method used, not on the regex's flags.

scan will return an array containing (or iterate over) all matches of the regex. match and String#[] will return the first match. =~ will return the index of the first match. gsub will replace all occurrences of the regex and sub will replace the first occurence.


smotchkkiss:~$ irb
>> 'Foobar does not like food because he is a fool'.gsub(/foo/i, 'zim')
=> "zimbar does not like zimd because he is a ziml"
0

精彩评论

暂无评论...
验证码 换一张
取 消