1

I have some confusion in Regex so I need help.my question is I am using the following Regex to prevent string should not start with some character and should not contain angular bracket.this regex also preventing next line as well so can u help me to modify it according to my need.

^(?![@=+*-])(?!.*[<>]).*$

Thanks working example-->https://regex101.com/r/5GZQl7/1

Manish
  • 849
  • 4
  • 14

1 Answers1

1

The problem with your regex is that . does not match line endings, so as soon as you put a new line in there, the regex does not match.

Ideally, we want it to match everything, including line endings. What syntax can match everything? One way to do this is to use complementing character sets. \s matches all the whitespace, \S matches all the non-whitespace, so [\s\S] will match everything!

Replace all your .s with [\s\S]!

Demo

Sweeper
  • 145,870
  • 17
  • 129
  • 225