In actionscript, how to check if a given regular expression is compiled or not using the RegExp class

I am new to actionscript working on avm2 ..

One thing I want to know is to determine if a given regular expression is compiled or not in the RegExp class, which uses the pcre library internally as a regular expression compiler.

For example, the following has parenthesized-inconsistent regular expression that might not compile in pcre in the RegExp class.

var r:RegExp = new RegExp("(a))"); 

I tried using try-catch as shown below, there was no exception.

 try { var r:RegExp = new RegExp("(a))"); } catch (e:Error) { trace('error'); } 

I also tried to find a solution on the Internet, it seems there is no method or properties for it.

Thanks.

+4
source share
1 answer

According to the documentation , an error in the regular expression will raise a SyntaxError :

A parsing exception occurs when a parsing error occurs for one of the following reasons:

& bull; An invalid regular expression is parsed by the RegExp class.

& bull; Invalid XML content is parsed by the XML class.

As a subclass of Error your code should have caught it, but in my testing it looks broken .

0
source

All Articles