Reputation: 114016
I've got a couple of regex's in AS3 that are defined with the inline AS3 regex syntax like:
/\/\*[\s\S]*?\*\//gm
I want to convert that to the AS3 RegEx class constructor like:
new RegExp('/\/\*[\s\S]*?\*\//', "gm")
I'm not sure if I have to escape the backslashes or not. Do you know how to convert it?
/** ------------------------- Regular Expressions ---------------------------- */
public static var multiLineCComments:RegExp = /\/\*[\s\S]*?\*\//gm;
public static var singleLineCComments:RegExp = /\/\/.*$/gm;
public static var singleLinePerlComments:RegExp = /#.*$/gm;
public static var doubleQuotedString:RegExp = /"([^\\"\n]|\\.)*"/g;
public static var singleQuotedString:RegExp = /'([^\\'\n]|\\.)*'/g;
public static var multiLineDoubleQuotedString:XRegExp = new XRegExp('"([^\\\\"]|\\\\.)*"', 'gs');
public static var multiLineSingleQuotedString:XRegExp = new XRegExp("'([^\\\\']|\\\\.)*'", 'gs');
public static var xmlComments:RegExp = /(<|<)!--[\s\S]*?--(>|>)/gm;
public static var url:RegExp = /\w+:\/\/[\w-.\/?%&=:@;]*/g;
Upvotes: 2
Views: 808
Reputation: 114016
I understood how to do it.
Delete the first and last /
which is the part of the AS3 regex syntax.
Place the ending options such as g
or gm
in the 2nd argument.
And lastly escape every backslash (\
) by replacing it with 2 backslashes
So in summary:
/\/\*[\s\S]*?\*\//gm
new RegExp ("\\/\\*[\\s\\S]*?\\*\\/", 'gm')
Upvotes: 1
Reputation: 5978
You could do this another way:
private static const pattern:RegExp = /\/\*[\s\S]*?\*\//;
public static var regex:XRegExp = new XRegExp(pattern.source, "gm");
Upvotes: 0