What would be regex for matching foreign characters?

后端 未结 3 1621
天涯浪人
天涯浪人 2020-12-07 01:25

I am dealing with developing and Application for European Client and they have their native character set.

Now I need to have regex which would allow foreign charac

相关标签:
3条回答
  • 2020-12-07 01:44

    \p{L} isn't cross-browser yet. Transpiling down from this will give you massively bloated code if you use it a lot.

    Here is a short and sweet answer to generally including non-ascii letters that doesn't add a gazillion lines of JavaScript or plugins. Replace a-zA-Z0-9 or \w in your regex with this, and don't use the u flag:

    \u00BF-\u1FFF\u2C00-\uD7FF\w

    This inserted into all my JavaScript regexes in place of a-zA-Z0-9 or \w, seems to do the job. My context was in the discerning of UTF-8 in HTML and CSS, and it had to be cross-browser.

    I can't believe it is this simple, so am waiting to be proved wrong, after a day's searching of trying to get something to work in Firefox...

    I've only tested this using Japanese hirigana with a french accent.

    0 讨论(0)
  • 2020-12-07 01:57

    [e\xE8\xE9\xEA\xEB] will match any one of eéèêë

    0 讨论(0)
  • 2020-12-07 02:04

    If all you want to match is letters (including "international" letters) you can use \p{L}.

    You can find some information on regex and Unicode here.

    0 讨论(0)
提交回复
热议问题