What regex matches all strings except ones starting with a literal /*
, meaning a slash (U+002F
) followed by a star (U+002A
)?
I’ve tried ^.*[^/\*]
but it doesn’t seem to work for me.
To check if a string does not start with specific characters using a regular expression, use the test() function and negate it. Make sure your regular expression starts with ^ , which is a special character that represents the start of the string.
Basically (0+1)* mathes any sequence of ones and zeroes. So, in your example (0+1)*1(0+1)* should match any sequence that has 1. It would not match 000 , but it would match 010 , 1 , 111 etc. (0+1) means 0 OR 1.
$ means "Match the end of the string" (the position after the last character in the string). Both are called anchors and ensure that the entire string is matched instead of just a substring.
The (?!...) part means "only match if the text following (hence: lookahead) this doesn't (hence: negative) match this. But it doesn't actually consume the characters it matches (hence: zero-width). lookbehind / lookahead : specifies if the characters before or after the point are considered.
You can use a negative lookahead:
^(?!/\*).*
This will match everything except if it starts with /*
.
Or if you mean anything except /
or *
:
^[^/*].*
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With