简体   繁体   中英

Regex match multibyte numbers

I need to match multi-byte 0123456789 characters from Japanese using a regular expression.

[0-9] does not work in this case. How can I got about making this regex? This is my first foray into matching multi-byte strings.

UPDATE

Matching a 4 digit string, such as birth year, was successful with both UTF-8 and non UTF-8 using the following regex

^([0-9]{4}||[\0-\9]{4})$

对于Javascript中的这些多字节数,正则表达式相当于/[0-9]/

/[\uff10-\uff19]/
var str = '0123456789';
console.log(
    str.match(new RegExp('[0-9]', 'g')),
    str.match(/[\uff10-\uff19]/g) 
);
//returns ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] both ways

Make sure to save the .js file with the proper encoding (UTF-8) if using the unescaped version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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