RegEx to find two or more consecutive chars

后端 未结 4 1146
小鲜肉
小鲜肉 2020-12-24 04:36

I need to determine if a string contains two or more consecutive alpha chars. Two or more [a-zA-Z] side by side. Example:

\"ab\" -> valid
\"a         


        
相关标签:
4条回答
  • 2020-12-24 04:41

    This should do the trick:

    [a-zA-Z]{2,}
    
    0 讨论(0)
  • 2020-12-24 04:45

    Personnaly (as a nooby) I've used:

    [0-9][0-9]+.
    

    But the one from Simon, is way better ! =D

    0 讨论(0)
  • 2020-12-24 04:51

    I'm pretty sure you can just use [A-z] instead of the [a-zA-Z] to get small and upper case alpha chars http://www.w3schools.com/jsref/jsref_obj_regexp.asp

    0 讨论(0)
  • 2020-12-24 05:04

    [a-zA-Z]{2,} does not work for two or more identical consecutive characters. To do that, you should capture any character and then repeat the capture like this:

    (.)\1

    The parenthesis captures the . which represents any character and \1 is the result of the capture - basically looking for a consecutive repeat of that character. If you wish to be specific on what characters you wish to find are identical consecutive, just replace the "any character" with a character class...

    ([a-zA-Z])\1

    Finds a consecutive repeating lower or upper case letter. Matches on "abbc123" and not "abc1223". To allow for a space between them (i.e. a ab), then include an optional space in the regex between the captured character and the repeat...

    ([a-z]A-Z])\s?\1

    0 讨论(0)
提交回复
热议问题