R 如何使用正则表达式提取用于词性标记的字符串

R 如何使用正则表达式提取用于词性标记的字符串,r,regex,R,Regex,对于以下示例,我在解决该问题时面临一些困难 "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 D

对于以下示例,我在解决该问题时面临一些困难

 "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 ./." 

由于在“t”和连字符“CAD支持”中使用撇号,因此结果并不像预期的那样。我根据要求将此作为新查询发布。谁能帮我解决这个问题。谢谢

如果要使用以前的解决方案,只需将正则表达式更改为

[^\s/]+
代码:

str_extract_all(str1, "[^\\s/]+")
str_extract_all(str1, "\\w+(?:['-]\\w+)*")

它将匹配除空格和
/
之外的1个或多个字符

为了避免匹配
/
,您需要使用

\w+(?:['-]\w+)*
代码:

str_extract_all(str1, "[^\\s/]+")
str_extract_all(str1, "\\w+(?:['-]\\w+)*")
这将匹配1+个单词字符,后跟0+个
'
序列,或
-
后跟1+个单词字符。看