douye2488 2018-05-17 01:52
浏览 17
已采纳

如何在PHP中构建正则表达式,包含字母和重音/ circumflex / etc字符?

I have never worked with regular expressions. And now, at my job, I need a regular expression that accepts a string with:

(It is a full name that can have so many variants and many languages)

  • Blank spaces
  • Any quantity of numbers
  • Any quantity of alphabetic characters, including grave, acute, circumflex, tilde, diaresis, ring above, cedilla, etc. This is all variants of each letter. Example (A, À, Á, Â, Ã, Ä, Å)
  • Latin special characters (ñ Ñ, ç Ç)
  • German special character (ß)
  • En dash (-)

I am reading and studying documentation now, but I am stuck.

  • 写回答

1条回答 默认 最新

  • dsg435665475 2018-05-17 01:59
    关注

    You could use something like this:

    ^[0-9\wÀ-ž\s\-]+$
    
    • 0-9 for numbers

    • \w for word characters

    • À-ž for the special characters

    • \s for spaces

    • \- for the -

    wrapping this inside [] makes an class, which maches everything inside and putting a + after the class, says at least one element of this character class.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部