The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
EulerChen

Golang 如何写出同时包含字母和数字的正则?

  •  
  •   EulerChen ·
    ApsarasX · Sep 1, 2019 · 5833 views
    This topic created in 2471 days ago, the information mentioned may be changed or developed.

    网上的答案都是基于断言来表示的,但是 Golang 的正则不支持断言……

    8 replies    2019-10-05 20:36:17 +08:00
    wweir
        1
    wweir  
       Sep 2, 2019 via Android
    (\d+\s+.*|\s+\d+.*)
    手机手撸,没试过
    AddictX
        2
    AddictX  
       Sep 2, 2019
    同时包含字母数字?
    [a-zA-z0-9]* 就可以啊。
    msg7086
        3
    msg7086  
       Sep 2, 2019 via Android
    @AddictX 你再想想?
    neoblackcap
        4
    neoblackcap  
       Sep 2, 2019
    \w*
    ahsjs
        5
    ahsjs  
       Sep 2, 2019
    同时包含要考虑下顺序
    有可能数字在前字母在后或者字母在前数字在后
    (\d+.*[a-zA-Z]+)|([a-zA-Z]+.*\d+)
    reus
        6
    reus  
       Sep 3, 2019
    用两条,一条匹配字母,一条匹配数字,然后 &&
    aliipay
        7
    aliipay  
       Oct 5, 2019
    (\d+\S*[a-z])|([a-z]+\S*\d)\S*
    aliipay
        8
    aliipay  
       Oct 5, 2019
    @aliipay 忽略我的吧,楼上已经有比我更优的答案了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   855 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 20:39 · PVG 04:39 · LAX 13:39 · JFK 16:39
    ♥ Do have faith in what you're doing.