[英]How to match regexp starting from specific character index in Ruby 1.8?
[英]How to match all character exept dot using regexp in ruby?
给定字符串:
I can haz kittens. Mmmm. Tasty, tasty kittens.
我需要得到:
#without dot
I can haz kittens Mmmm Tasty, tasty kittens
我写:
string = 'I can haz kittens. Mmmm. Tasty, tasty kittens.'
/[^\.]*/.match(string)
接下来,我不知道。
您只需要String#delete
:
"I can haz kittens. Mmmm. Tasty, tasty kittens.".delete('.')
如果您确实想使用正则表达式,则可以使用String#gsub
:
"I can haz kittens. Mmmm. Tasty, tasty kittens.".gsub(/\./,'')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.