So [^x]
means don't match "x", and x*
means match "x" 0 or more times, but what does [^*]
mean?
*$ 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.
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.
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.
To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ).
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: \.
.
*
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 $
".
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