-3

I have to use a regex to verify if a string is not empty or blank, and doesn't contain ">" "<".

For example:

enter image description here

  1. " " is invalid;

  2. " a <" is invalid;

  3. " a 6" is OK;

I tried below regex, but doesn't work.


^(^\s*$)|^[^<,>]+$


How could I set this regex? could any kind guys help me on this? thanks.

AdvancingEnemy
  • 382
  • 3
  • 20

1 Answers1

1

Try

^(?!\s+$)[^<>]+$
  • ^...$ - String should start and end with... (matching whole string/line)
    • (?!...) - Negative lookahead, string should not be followed by...
      • \s+$ - One or more whitespace characters until the end of the string
    • [^<>]+ - Any character except < and >, one or more times

Live demo

Ivar
  • 6,138
  • 12
  • 49
  • 61