Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex for strings not starting with "/*"

Tags:

regex

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.

like image 971
smallB Avatar asked Jan 05 '12 17:01

smallB


People also ask

Does not start with string regex?

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.

What does regex 0 * 1 * 0 * 1 * Mean?

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.

What does '$' mean in regex?

$ 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.

How do you write not condition in regex?

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.


1 Answers

You can use a negative lookahead:

^(?!/\*).*

This will match everything except if it starts with /*.

Or if you mean anything except / or *:

^[^/*].*
like image 90
Howard Avatar answered Oct 01 '22 23:10

Howard