douseda0009 2011-07-30 12:00
浏览 54
已采纳

PHP正则表达式来破译英文和中文字符

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条回答 默认 最新

  • douwei3863 2011-07-30 12:15
    关注

    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. ;)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Opencv(C++)异常
  • ¥15 VScode上配置C语言环境
  • ¥15 汇编语言没有主程序吗?
  • ¥15 这个函数为什么会爆内存
  • ¥15 无法装系统,grub成了顽固拦路虎
  • ¥15 springboot aop 应用启动异常
  • ¥15 matlab有关债券凸性久期的代码
  • ¥15 lvgl v8.2定时器提前到来
  • ¥15 qtcp 发送数据时偶尔会遇到发送数据失败?用的MSVC编译器(标签-qt|关键词-tcp)
  • ¥15 cam_lidar_calibration报错