Specifying a Unicode Range in an ActionScript Regular Expression

I am trying to write a regular expression that will match all characters of a Unicode word, for example:

/[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF\w]/gi

But this completely fails and nothing matches. I have tried various expressions, and it seems that as soon as I try to specify a range, it fails. How am I more fortunate?

I would like ActionScript to suggest something like \ p {L}, but if something like that, I could not find it in the document.

+3
source share
3 answers

You can use String.fromCharCode with Unicode characters, and then the ranges will work correctly in the regular expression. Here is an example of using your original problem:

var exp:RegExp = new RegExp("[" + generateRangeForUnicodeVariables(0x00A0, 0xD7FF) + generateRangeForUnicodeVariables(0xF900, 0xFDCF) + generateRangeForUnicodeVariables(0xFDF0, 0xFFEF) + "\w]", "gi");

private function generateRangeForUnicodeVariables(var1:Object, var2:Object):String
{
   return String.fromCharCode(var1) + "-" + String.fromCharCode(var2);
}
+3
source

- , , , :

Unicode RegExp?

, , JavaScript, ExternalInterface .

+1

Hm. It doesn't seem to be about ranges, but about multibyte characters.

It works:

 var exp:RegExp = new RegExp("[\u00A0-\u0FCF]", "gi");
 var str:String = "\u00A1 \u00A2 \u00A3 \u00A3";
 trace("subject:", str);
 trace("match:", str.match(exp));

And this is not so:

 var exp:RegExp = new RegExp("[\u00A0-\u0FD0]", "gi");
 var str:String = "\u00A1 \u00A2 \u00A3 \u00A3";
 trace("subject:", str);
 trace("match:", str.match(exp));

In any case, you can use the RegExp constructor, which converts the string to the appropriate template.

0
source

All Articles