nazor
V2EX  ›  问与答

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

  •  
  •   nazor · Jul 6, 2013 · 3077 views
    This topic created in 4696 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
        1
    luikore  
       Jul 6, 2013
    apple =~ /[asd]/
    Mutoo
        2
    Mutoo  
       Jul 6, 2013
    javascript case:
    /[asd]/.test("apple"); // true
    013231
        3
    013231  
       Jul 6, 2013
    正则表达式30分钟入门教程: http://deerchao.net/tutorials/regex/regex.htm
    explon
        4
    explon  
       Jul 6, 2013
    为什么楼上的第一反映都是正则?

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