问题
I have a description which is in English and Chinese.
How would I go about using regex to say something like, if the line contains a Chinese character then do A, else do B ?
example here
电源: 110V/220W50-60HZ
功率:60W
光源:12V 150 W
尺寸:220x150x280mm
重量:2.3KG
Voltage : 110V/220W50-60HZ
Power : 60W
Bulb : 12V 150 W
Size : 220x150x280mm
Weight:2.3KG
回答1:
Chinese characters are within the range: U+4E00..U+9FFF
If your expreg extension has been built with Unicde support, b\p{InCJK_Unified_Ideographs}
is a good replacement for [\x{4E00}-\x{9FFF}]
(which was in the link Jens Struwe gave).
You can find most (all?) of Unicode ranges here: http://www.regular-expressions.info/unicode.html
I'm not sure what you want to achieve, but maybe a good start would be split your description by line. Then, for each line, find whether it's Chinese or not, and run the appropriate regex. ;)
来源:https://stackoverflow.com/questions/6882967/php-regex-to-to-decipher-english-and-chinese-characters