AS3正则表达式用在他们的边界类型字符匹配的话 [英] AS3 RegExp to match words with boundry type characters in them

查看:151
本文介绍了AS3正则表达式用在他们的边界类型字符匹配的话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想匹配的单词列表是很容易的,当这些话是真的话。例如 / \ 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.

这篇关于AS3正则表达式用在他们的边界类型字符匹配的话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆