Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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 如何用空格字符对词素入句?_Regex - Fatal编程技术网

Regex 如何用空格字符对词素入句?

Regex 如何用空格字符对词素入句?,regex,Regex,例如-句子,其中|是句子边界。在句子末尾,在字符后定位字符空格: |This is one. | 如何拆分此字符串如何: [This ] [is ] [one. ] 我做什么(正则表达式): Regex1: (\.\s|\s) (?<=[\s\p{Punct}]) 0: [This ] 1: [is ] 2: [one.] 3: [ ] 结果: 0: [This] 1: [is] 2: [one] Regex2: (\.\s|\s) (?<=[\s\p{Punct}])

例如-句子,其中
|
是句子边界。在句子末尾,在字符
后定位字符空格

|This is one. |
如何拆分此字符串如何:

[This ]
[is ]
[one. ]
我做什么(正则表达式):
Regex1:

(\.\s|\s)
(?<=[\s\p{Punct}])
0: [This ]
1: [is ]
2: [one.]
3: [ ]
结果:

0: [This]
1: [is]
2: [one]
Regex2:

(\.\s|\s)
(?<=[\s\p{Punct}])
0: [This ]
1: [is ]
2: [one.]
3: [ ]
但是它不能正确地分隔单词。

正则表达式:

(?<=[\s])
返回结果:

0: [This ]
1: [is ]
2: [one. ]
正则表达式:

返回结果:

0: [This ]
1: [is ]
2: [one. ]

您可以使用
进行拆分(?您可以使用
进行拆分(?您尚未指定使用哪个正则表达式引擎。因此,很难给出确切的解决方案

pcre中需要的拆分正则表达式如下所示


(?您尚未指定使用哪个正则表达式引擎。因此,很难给出确切的解决方案

pcre中需要的拆分正则表达式如下所示


(?非常感谢:)非常感谢:)