2

我在 AS3 中有一个正则表达式。直到现在它一直在工作,但现在我想从一开始就排除一个短语。具体来说,原文是:

var pattern:RegExp = new RegExp(keyword,'/gi');

我正在尝试按照以下方式做一些事情:

var pattern:RegExp = new RegExp(!'<a href=\"event:' + keyword,'/gi');

在哪里

baaah

会工作,但是

<ahref="event:baaah

行不通。

请帮忙!在我的代码中实现的正确语法是什么。

4

1 回答 1

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.
于 2012-09-03T05:55:01.450 回答