正则表达式在ActionScript 3:如何排除复杂preFIX? [英] RegExp in ActionScript 3: How to exclude a complex prefix?

查看:193
本文介绍了正则表达式在ActionScript 3:如何排除复杂preFIX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AS3正则表达式引擎(和ECMAScript基于JavaScript的)不支持的复杂后向EX pressions。 (超前的前pressions完全支持。)

例如:

 (?< =<身体GT;)(。*?)(=< \ /身体GT;)
 

将工作,但;

 (?< =<车身\ B〔^>] *>)(。*?)(=< \ /身体GT;)
 

不能在AS3工作。

我需要的是匹配一个复杂的preFIX,但排除在最后一场比赛。 在上面的例子;我试图让身体内容的HTML文本而不是打开和关闭body标签。而实际的测试文字是这样的:

 <身体BGCOLOR =#EEEEEE>
有些内容在这里...
< /身体GT;
 

解决方案

我想你想 VAR的正则表达式:正则表达式= /<body>(.*?)<\/body>/i ; 相对于3组在当前的正则表达式,所以你只能捕捉body标签,你可以再引用匹配任何\ 1或$ 1,这取决于功能,您使用的是:

http://livedocs.adobe.com/flex/3/html/help.html?content=12_Using_Regular_Ex$p$pssions_09.html

AS3 RegExp engine (and ECMAScript based JavaScript) do not support complex "lookbehind" expressions. (lookahead expressions are fully supported.)

For example:

 (?<=<body>)(.*?)(?=<\/body>)

will work but;

(?<=<body\b[^>]*>)(.*?)(?=<\/body>)

will not work in AS3.

What I need is to match a complex prefix but exclude it in the final match. In the example above; I'm trying to get the body contents in an HTML text but NOT the opening and closing body tags. And the actual test text looks like this:

<body bgcolor="#EEEEEE">
Some content here...
</body>

解决方案

I think you want var regExp:RegExp = /<body>(.*?)<\/body>/i; as opposed to the 3 groups in your current regexp, so you're only capturing the body tag, you can then reference the match with either \1 or $1 depending on which function you're using:

http://livedocs.adobe.com/flex/3/html/help.html?content=12_Using_Regular_Expressions_09.html

这篇关于正则表达式在ActionScript 3:如何排除复杂preFIX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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