Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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
Ruby 使用regexp将句子拆分为单词_Ruby_Regex_String - Fatal编程技术网

Ruby 使用regexp将句子拆分为单词

Ruby 使用regexp将句子拆分为单词,ruby,regex,string,Ruby,Regex,String,我正在努力做到以上几点。例如: "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all." 应分成单独的单词: This is a sentence I'm 等等 我只是在努力写regexp。我知道使用一两个分隔符很容易,但要想了解更多关于regexp的信息,只需根据一个或多个空格字符分割输入即可 > "Thi

我正在努力做到以上几点。例如:

"This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all."
应分成单独的单词:

This
is 
a
sentence
I'm
等等


我只是在努力写regexp。我知道使用一两个分隔符很容易,但要想了解更多关于regexp的信息,只需根据一个或多个空格字符分割输入即可

> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".split(/\s+/)
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]

> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".split()
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]
> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".scan(/\S+/)
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]

匹配一个或多个非空格字符

> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".split(/\s+/)
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]

> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".split()
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]
> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".scan(/\S+/)
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]

只需根据一个或多个空格字符分割输入

> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".split(/\s+/)
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]

> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".split()
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]
> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".scan(/\S+/)
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]

匹配一个或多个非空格字符

> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".split(/\s+/)
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]

> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".split()
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]
> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".scan(/\S+/)
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]

只需根据一个或多个空格字符分割输入

> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".split(/\s+/)
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]

> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".split()
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]
> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".scan(/\S+/)
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]

匹配一个或多个非空格字符

> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".split(/\s+/)
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]

> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".split()
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]
> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".scan(/\S+/)
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]

只需根据一个或多个空格字符分割输入

> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".split(/\s+/)
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]

> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".split()
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]
> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".scan(/\S+/)
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]

匹配一个或多个非空格字符

> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".split(/\s+/)
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]

> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".split()
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]
> "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all.".scan(/\S+/)
=> ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."]
使用

使用循环在每行上框定一个单词

2.0.0-p481 :036 > a="This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all."
 => "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all." 
2.0.0-p481 :037 > a.split.each{ |i|  puts "#{i}"}
This
is
a
sentence
I'm
currently
writing,
potentially
with
punctuation
dotted
in:
item1,
item2,
item3.
That
is
all.
 => ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."] 
2.0.0-p481 :038 >
使用

使用循环在每行上框定一个单词

2.0.0-p481 :036 > a="This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all."
 => "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all." 
2.0.0-p481 :037 > a.split.each{ |i|  puts "#{i}"}
This
is
a
sentence
I'm
currently
writing,
potentially
with
punctuation
dotted
in:
item1,
item2,
item3.
That
is
all.
 => ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."] 
2.0.0-p481 :038 >
使用

使用循环在每行上框定一个单词

2.0.0-p481 :036 > a="This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all."
 => "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all." 
2.0.0-p481 :037 > a.split.each{ |i|  puts "#{i}"}
This
is
a
sentence
I'm
currently
writing,
potentially
with
punctuation
dotted
in:
item1,
item2,
item3.
That
is
all.
 => ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."] 
2.0.0-p481 :038 >
使用

使用循环在每行上框定一个单词

2.0.0-p481 :036 > a="This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all."
 => "This is a sentence I'm currently writing, potentially with punctuation dotted in: item1, item2, item3. That is all." 
2.0.0-p481 :037 > a.split.each{ |i|  puts "#{i}"}
This
is
a
sentence
I'm
currently
writing,
potentially
with
punctuation
dotted
in:
item1,
item2,
item3.
That
is
all.
 => ["This", "is", "a", "sentence", "I'm", "currently", "writing,", "potentially", "with", "punctuation", "dotted", "in:", "item1,", "item2,", "item3.", "That", "is", "all."] 
2.0.0-p481 :038 >

只需根据这个
\s+
正则表达式进行拆分。或者使用
string.split()。你的问题模棱两可。在那之后我们不能告诉你你想要什么。还有,你的问题是什么?你想
写,
还是
在:
还是
中?只需根据这个
\s+
正则表达式进行拆分。或者使用
string.split()。你的问题模棱两可。在那之后我们不能告诉你你想要什么。还有,你的问题是什么?你想
写,
还是
在:
还是
中?只需根据这个
\s+
正则表达式进行拆分。或者使用
string.split()。你的问题模棱两可。在那之后我们不能告诉你你想要什么。还有,你的问题是什么?你想
写,
还是
在:
还是
中?只需根据这个
\s+
正则表达式进行拆分。或者使用
string.split()。你的问题模棱两可。在那之后我们不能告诉你你想要什么。还有,你的问题是什么?你想
写,
还是
在:
还是
中?