nazor
V2EX  ›  问与答

如何搜索一个字符串中是否存在某些字符中的任意一个

  •  
  •   nazor · Jul 6, 2013 · 3304 views
    This topic created in 4869 days ago, the information mentioned may be changed or developed.
    比如说 判断 apple 中 是否存在 a s d 这三个字符中的任意一个。

    谢谢指导。
    6 replies  •  1970-01-01 08:00:00 +08:00
    luikore
    luikore
    Jul 6, 2013
    1
    apple =~ /[asd]/
    Mutoo
    Mutoo
    Jul 6, 2013
    2
    javascript case:
    /[asd]/.test("apple"); // true
    013231
    013231
    Jul 6, 2013
    3
    正则表达式30分钟入门教程: http://deerchao.net/tutorials/regex/regex.htm
    explon
    explon
    Jul 6, 2013
    4
    为什么楼上的第一反映都是正则?

    Javascript: indexOf()
    PHP: strstr()
    switch
    switch
    Jul 6, 2013
    5
    @explon 楼主要求测三个中的其中一个,indexOf 在这里不太合适。
    nazor
    nazor
    OP
    Jul 10, 2013
    6
    谢谢大家 发现一个个找的效率还可以
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3766 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 05:27 · PVG 13:27 · LAX 21:27 · JFK 00:27
    ♥ Do have faith in what you're doing.