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

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

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

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

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