参考question https://stackoverflow.com/questions/44434739/how-to-extract-a-string-before-and-after-slash-in-r,我在以下示例的解决方案中面临一些困难。
"I/PRP did/VBD n't/RB experienced/VBN much/JJ service/NN differentiation/NN" The/DT desktop/NN and/CC CAD/NN support/NN is/VBZ working/VBG as/IN expected/VBN CAD-support/NNP Desktop/NNP management/NN related/VBD to/TO LSB/NNP Desktop/NNP management/NN team/NN is/VBZ very/RB committed/VBN ./."
由于“n't”中有撇号和连字符“CAD-Support”,结果未按预期出现。我根据要求将此作为新查询发布。谁能帮我解决这个问题。谢谢!!
如果您想使用以前的解决方案,您只需将正则表达式更改为
[^\s/]+
in code:
str_extract_all(str1, "[^\\s/]+")
See the 正则表达式演示 https://regex101.com/r/KTaONV/1.
它将匹配除空格之外的 1 个或多个字符,并且/
.
为了避免匹配./.
,你需要使用类似的东西
\w+(?:['-]\w+)*
in code:
str_extract_all(str1, "\\w+(?:['-]\\w+)*")
将匹配 1+ 个单词字符,后跟 0+ 个序列'
or -
后跟 1+ 个单词字符。看这个正则表达式演示 https://regex101.com/r/KWcce7/1.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)