作者:猫ranran | 来源:互联网 | 2023-05-17 15:40
Ihavestringsofthefollowingflavor:我有以下几种口味:RandomIncANon-RandomIncIwouldliketorem
I have strings of the following flavor:
我有以下几种口味:
Random Inc
A Non-Random Inc
I would like to remove the word Inc
from all those strings wehre there are more than 1 word preceding it. The result on the above two examples would be:
我想从所有的字符串中删除,因为前面有超过一个词。以上两个例子的结果是:
Random Inc
A Non-Random
What is the right regex to plug into gsub
for this? In particular, how does one specify complete words in regex? I thought it would be \w
but this is a word character which does not seem correct.
什么是正确的regex插入到gsub为此?特别是,如何在regex中指定完整的单词?我原以为是\w,但这是一个看起来不正确的字字符。
3 个解决方案