Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regular expression doesn't start with character A or whitespace [closed]

Tags:

regex

I want my regular expression to match strings that don't start with the letter A or whitespaces.
I've tried ^-|^(^(\W|A).), but it doesn't work, any ideas why?

like image 693
kamal mrad Avatar asked Nov 28 '22 01:11

kamal mrad


2 Answers

regular expression doesn't start with character A or whitespace

^(?![A\s])

To match the whole string, you need to add .*

^(?![A\s]).*

OR

^[^A\s].*

DEMO

Strings don't start with A or Space will match also the strings starts with hyphen -, so you don't need to specify the pattern for strings starting with hyphen.

like image 130
Avinash Raj Avatar answered Dec 06 '22 04:12

Avinash Raj


You were close:

^[^ A]
  • [^ A] matches anything other than A or space

  • ^ anchors the regex at start of the string

Regex Example

like image 45
nu11p01n73R Avatar answered Dec 06 '22 06:12

nu11p01n73R