-3

What is the regex to get strings with one or more word characters except strings with digit only characters? For example, "word", "word1" match the regex but "1" doesn't. Thanks!

Fei Qu
  • 121
  • 1
  • 9
  • Your question is contradictory. According to normal definition, a digit is a word character. `"1".match?(/\w/) # => true`. Otherwise, if you have your own definition, then please define it. – sawa Feb 01 '19 at 04:36

1 Answers1

-1

Try this:

/\A(?!\d+\z)\w+\z/

Description:

  1. \A - start of string

  2. (?!\d+\z) - negative lookahead

Using ?! means not matching given pattern

\d+ - one or more digits

\z - end of string

So if only digit(s) - pattern will not match

  1. \w+ - one or more word characters

  2. \z - end of string

mechnicov
  • 12,025
  • 4
  • 33
  • 56