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 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探