指定UNI code范围内的动作经常EX pression [英] Specifying a unicode range in an actionscript regular expression
问题描述
我一直在试图写一个普通的前pression,将匹配所有UNI code字字符是这样的:
I have been trying to write a regular expression that would match all unicode word character something like :
/[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF\w]/gi
不过这完全失败,并且不匹配任何东西。我已经尝试了多种前pressions,似乎只要我尝试指定范围的失败。正如有人比我幸运了?
But this completely fails and doesn't match anything. I have tried a variety of expressions and it seems that as soon as I try to specify a range it fails. As anyone been luckier than me?
我希望动作会提供类似\ p {L〕,但如果有任何东西之类的,我无法找到它的文档。
I wish actionscript would offer something like \p{L}, but if there's anything in the like, I couldn't find it in the doc.
推荐答案
您可以使用String.fromChar code与UNI code字符,然后范围将在常规的前pression正常工作。下面是使用你原来的问题的例子:
You can use String.fromCharCode with the unicode characters and then the ranges will work correctly in a regular expression. Here is an example 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);
}
这篇关于指定UNI code范围内的动作经常EX pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!