我目前正在使用此REGEX来获取前缀为PRE_的整个单词
\b(PRE_)\S*
这适用于大多数情况,但我想处理特殊字符是单词的一部分时的情况,例如句号,逗号或其他特殊字符。,; - {}()[]
例如,这里的话:
PRE_samplewordwithoutdelimiter
PRE_sampleword.otherwordsnotincluded;
PRE_Sampleword{}...deleted
PRE_complexword()a.;.is deleted
Somewords ahead PRE_sometext() ending in other words
Words with bracket [PRE_brackettext] are deleted
PRE_sampleword is spaced out so deleted
sampleword.PRE_deleted;
notdeleted.notdeleted.PRE_
我只希望找到一个分隔词的第一部分。所以我可以删除或替换这个词。因此,在使用“”作为文本替换此场景中的所有PRE_前缀单词的情况下,我会得到:
<DELETED>
<DELETED>.otherwordsnotincluded;
<DELETED>{}...deleted
<DELETED>()a.;.is deleted
Somewords ahead <DELETED>() ending in other words
Words with bracket [<DELETED>] are deleted
<DELETED> is spaced out so deleted
sampleword.<DELETED>;
notdeleted.notdeleted.<DELETED>
我正在尝试不同的REGEX,但在整个样本中没有任何真正匹配完全正确。像下面这样的东西不起作用:
\b(PRE_)\S*(?:[;]|[.][-])$
这里的任何帮助将不胜感激。