简体   繁体   English

javascript正则表达式对带有数字和字母的UTF8字符的支持

[英]javascript regex support for UTF8 characters with Number and letters

How to generate regex for supporting utf8 characters with Numbers [0-9], letters [az] and [AZ]. 如何生成正则表达式以支持数字[0-9],字母[az]和[AZ]的utf8字符。

I am using xregexp library to support utf-8 characters. 我正在使用xregexp库来支持utf-8字符。

Till now i used : 直到现在我用:

  1. XRegExp("^\\p{L}\\d{0-9}+$") //Not supporting any of them. XRegExp(“ ^ \\ p {L} \\ d {0-9} + $”)//不支持任何一个。
  2. XRegExp("[^\\p{N}\\p{L}]") //Not supporting any of them. XRegExp(“ [^ \\ p {N} \\ p {L}]”)//不支持任何一个。
  3. XRegExp("^\\p{L}+$") // Supports only UTF-8 characters, [az] and [AZ] and not [0-9] XRegExp(“ ^ \\ p {L} + $”)//仅支持UTF-8字符[az]和[AZ],不支持[0-9]

Thanks. 谢谢。

Just use \\\\p{L}+ in combination with [0-9] : 只需将\\\\p{L}+[0-9]结合使用:

XRegExp("^(\\p{L}|[0-9])+$")

Note that you need to escape your backslash, there: \\\\ . 请注意,您需要在以下位置转义反斜杠: \\\\

To include _/- : 要包含_/-

XRegExp("^(\\p{L}|[0-9_/-])+$")

Note that the dash ( - ) has to be the first or last character in those brackets, due to it's special meaning. 请注意,由于特殊含义,破折号( - )必须是这些括号中的第一个或最后一个字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM