Negate characters in Regular Expression

后端 未结 4 1998
醉话见心
醉话见心 2020-11-30 10:43

How would I write a regular expression that matches the following criteria?

  • No numbers
  • No special characters
  • No spaces

in a st

4条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 11:25

    In Perl, it would be something like:

    $string !~ /[\d \W]/
    

    Of course, it depends on your definition of "special characters". \W matches all non-word characters. A word character is any alphanumeric character plus the space character.

提交回复
热议问题