0

I have the regular expression:

 ^[-\s]+|Not Specified$

I get a match on all of the following strings:

--
Not Specified
- - -                    eV
-270 - 1000                    deg C

but I want to get only on the first three.

I don't want to catch word like:

 MTF, Depth, Focus, Blur
sub-micron
user3541631
  • 3,686
  • 8
  • 48
  • 115

2 Answers2

1

You need to add parenthesis. The \D matches anything other than a decimal digit:

^(\D+|Not Specified)$

You can even break down to:

^\D*$
Franky
  • 38
  • 5
1

You could match either Not Specified or match at least a single - without matching digits or a newline:

^(?:Not Specified|[^\r\n\d-]*-[^\r\n\d]*)$

Explanation

  • ^ Start of string
    • (?: Non capturing group
    • Not Specified Match literally
    • | Or
    • [^\r\n\d-]*- Match 0+ times any char except a digit, - or newline, then match -
    • [^\r\n\d]* Match 0+ times any char except a newline or digit
  • ) Close group
  • $ End of string

Regex demo

Note that \s also matches a newline, if that is intended you can omit the \r\n so that the negated character class will match thenewlines.

The fourth bird
  • 154,723
  • 16
  • 55
  • 70