Reputation: 938
How can I get Haxe to match parentheses in regular expressions?
I always get the error Invalid Escape Sequence
.
var reg = new EReg('\([0-9]+\)', 'i'); // Throws error
reg.match('(9)');
trace(reg.matched(0));
Upvotes: 2
Views: 361
Reputation: 34148
In strings, you need to escape the \
character using \\
. The following works:
var reg = new EReg('\\([0-9]+\\)', 'i');
Alternatively, Haxe has regex literals you can use here:
var reg = ~/\([0-9]+\)/i;
Upvotes: 4