fuhanfeng
V2EX  ›  问与答

匹配中文、英文和空格,但首位不允许空格,不能连续使用空格的正则

  •  
  •   fuhanfeng · Jun 1, 2015 · 3337 views
    This topic created in 4026 days ago, the information mentioned may be changed or developed.
    对写正则比较弱,希望大家帮忙写一个适用于PHP的正则,谢谢!
    3 replies    2015-06-01 17:33:35 +08:00
    imn1
        1
    imn1  
       Jun 1, 2015   ❤️ 1
    ^[A-Za-z\u4e00-\u9fcf](?:(?! )[A-Za-z \u4e00-\u9fcf]])+$
    没环境测试
    minuux
        2
    minuux  
       Jun 1, 2015
    preg_match('/^[^\d\W][\w]+$/iu', $str) ? TRUE : FALSE;
    minuux
        3
    minuux  
       Jun 1, 2015
    看错了,原来要可以使用空格...可以在那基础上稍微改下
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3133 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 15:03 · PVG 23:03 · LAX 08:03 · JFK 11:03
    ♥ Do have faith in what you're doing.