我想匹配的单词列表是很容易的,当这些话是真的话。例如 / \ B(流行|推送)\ B / GSX
时,对字符串跑
I'm wanting to match a list of words which is easy enough when those words are truly words. For example /\b (pop|push) \b/gsx
when ran against the string
弹出了门一推,但它突然出现回
pop gave the door a push but it popped back
将匹配单词流行和推动,但没有弹出。
will match the words pop and push but not popped.
我需要为包含通常有资格作为单词边界字符的话类似的功能。所以,我需要 / \ B(反|!推)\ B / GSX
时,对字符串跑
I need similar functionality for words that contain characters that would normally qualify as word boundaries. So I need /\b (reverse!|push) \b/gsx
when ran against the string
推逆转!逆转!推
要只匹配逆转!推而不能匹配逆转!推。显然,这正则表达式是不会做,这样做什么,我需要用\的B,而不是让我的正则表达式足够的智慧来处理这些时髦的要求?
to only match reverse! and push but not match reverse!push. Obviously this regex isn't going to do that so what do I need to use instead of \b to make my regex smart enough to handle these funky requirements?
目前一个字的结尾,\ B表示的previous字符是一个字符,和下一个字符(如果存在下一字符)不是一个单词字符要删除的第一个条件,因为有可能是在对字那给你留下一个负超前末尾的非单词字符:
At the end of a word, \b means "the previous character was a word character, and the next character (if there is a next character) is not a word character. You want to drop the first condition because there might be a non-word character at the end of the "word". That leaves you with a negative lookahead:
/\b (reverse!|push) (?!\w)/gx
我是pretty的肯定AS3正则表达式支持向前看。
I'm pretty sure AS3 regexes support lookahead.