doujing2497 2018-05-07 01:28
浏览 61
已采纳

允许在PHP中使用英语和俄语字符集的正则表达式[重复]

This question already has an answer here:

I have a contact form that is translated in both English and Russian. My client wants to be able to type Russian characters into the form fields as well as English. I am not great at regex and am hoping someone can help me adjust the regex I'm using to allow for the extra character set. I've already tried several different options I've found on here and none of them seem to be working. Which most likely means I'm not using it correctly. I'm using PHP and this is the regex for the first form input.

'/^[a-z][a-z ]*$/i'

I've tried it like this:

'/^[a-z][a-z ][\x{0410}-\x{042F}]*$/i'
'/^[a-z][a-z ][А-Яа-яЁё]*$/i'
'/^[a-z][a-z ][\p{Cyrillic}]*$/i'

But none of them seem to work.

</div>
  • 写回答

2条回答 默认 最新

  • dozr162106 2018-05-07 01:46
    关注

    Maybe because you didn't put them in the same bracket?

    (and the other question mentions the u flag)

    '/^[a-z][a-z А-Яа-яЁё]*$/iu'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?