Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does [^*] mean?

Tags:

So [^x] means don't match "x", and x* means match "x" 0 or more times, but what does [^*] mean?

like image 622
Nick Brunt Avatar asked Oct 15 '11 23:10

Nick Brunt


People also ask

What does *$ mean in regex?

*$ means - match, from beginning to end, any character that appears zero or more times. Basically, that means - match everything from start to end of the string.

What is meant by 1 in regex?

The backreference \1 (backslash one) references the first capturing group. \1 matches the exact same text that was matched by the first capturing group. The / before it is a literal character. It is simply the forward slash in the closing HTML tag that we are trying to match.

What is regex used for?

Regular expressions are particularly useful for defining filters. Regular expressions contain a series of characters that define a pattern of text to be matched—to make a filter more specialized, or general.

Why do we use backslash in regex?

To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ).


2 Answers

It means "match a character that isn't a literal asterisk character."

The thing to keep in mind is that within a character class metacharacters don't need to be escaped, so [^*] is the same as [^\*]. Similarly, you could use [.] to refer to a literal dot rather than the metacharacter referring to any character. Outside of a character class you would need to escape it: \..

like image 144
Ahmad Mageed Avatar answered Nov 07 '22 08:11

Ahmad Mageed


* doesn't have special meaning inside a character class, so it means literally "something that's not *". The only characters that have special meaning inside character classes are -, ^ and ]. Other than that everything is taken literally. For example, [^.] means "something that's not .", just as [^$] means "something that's not $".

like image 32
rid Avatar answered Nov 07 '22 07:11

rid