Regex: How to match a string that is not only numbers

后端 未结 11 823
夕颜
夕颜 2020-11-30 03:18

Is it possible to write a regular expression that matches all strings that does not only contain numbers? If we have these strings:

  • abc
11条回答
  •  时光说笑
    2020-11-30 03:54

    If we want to restrict valid characters so that string can be made from a limited set of characters, try this:

    (?!^\d+$)^[a-zA-Z0-9_-]{3,}$
    

    or

    (?!^\d+$)^[\w-]{3,}$
    

    /\w+/: Matches any letter, number or underscore. any word character

提交回复
热议问题