我在AS3中有一个正则表达式。直到现在它一直在工作,但现在我想从头开始排除一个短语。具体来说,原文是:
var pattern:RegExp = new RegExp(keyword,'/gi');
我正在尝试做一些事情:
var pattern:RegExp = new RegExp(!'<a href=\"event:' + keyword,'/gi');
其中
baaah
可行,但
<ahref="event:baaah
无效。
请帮忙!在我的代码中实现的正确语法是什么。
答案 0 :(得分:2)
请查看以下内容。
var myPattern:RegExp = /(?<=<a href='event:).+/;
var str:String = "<a href='event:baaah";
var result:Array = myPattern.exec(str);
trace(result[0]); //baaah
我强烈建议:Regular_expression
<强> Assertions
强>
- foo(?=bar) Lookahead assertion. The pattern foo will only match if
followed by a match of pattern bar.
- foo(?!bar) Negative lookahead assertion. The pattern foo will only
match if not followed by a match of pattern bar.
- (?<=foo)bar Lookbehind assertion. The pattern bar will only match if
preceeded by a match of pattern foo.
- (?<!foo)bar Negative lookbehind assertion. The pattern bar will only
match if not preceeded by a match of pattern foo.