Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何使用正则表达式拆分ruby字符串?_Regex_Ruby - Fatal编程技术网

Regex 如何使用正则表达式拆分ruby字符串?

Regex 如何使用正则表达式拆分ruby字符串?,regex,ruby,Regex,Ruby,嗨,我想把这个字符串分成以下几部分 text = "In the last summer, I visited the U.S. with my friend. It was great experience. I loved an ice cream in the U.S. Welcome to U.S.A. pal!" 显然,我无法应用text.split。也不是text.split。第一条规则是,字符串将被。除缩写词外。然而,我不知道如何在Ruby中做到这一点 似乎使用正则表达式可能有效

嗨,我想把这个字符串分成以下几部分

text = "In the last summer, I visited the U.S. with my friend. It was great experience. I loved an ice cream in the U.S. Welcome to U.S.A. pal!"
显然,我无法应用text.split。也不是text.split。第一条规则是,字符串将被。除缩写词外。然而,我不知道如何在Ruby中做到这一点


似乎使用正则表达式可能有效,但我不知道如何做到这一点。请分享您的想法好吗?

基本上,您希望在句点后以空格分隔,后跟大写字母:

text.split(/(?<=\.)\s+(?=[[:upper:]])/)

正则表达式将只匹配空格\s+,但请确保它前面有一个句点,并使用正向查找?基本上,您希望在句点后的空格处拆分,后跟一个大写字母:

text.split(/(?<=\.)\s+(?=[[:upper:]])/)
正则表达式将只匹配空格\s+,但是否确保它前面有一个使用正向查找的句点?