rolnn
rolnn

Reputation: 938

"Invalid Escape Sequence" with regex in Haxe

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));

http://try.haxe.org/#345D6

Upvotes: 2

Views: 361

Answers (1)

Gama11
Gama11

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

Related Questions