user3002486 user3002486 - 1 year ago 104
Python Question

Python regex expression, what does +X mean?

I'm having trouble figuring out what exactly this regex pattern is searching for mostly due to the number at the end. From what I can tell, it is saying search for any character that is not a-z and repeat it for the whole string. What does the 3 do?



Answer Source

In a character class all characters loose their special meaning (if any), only the first ^ is used to negate the class, - is used to define a range (except at the first and last position), an eventual backslash may start an escape sequence and ] closes the class.

3 is the literal character 3, + is the literal character +, . is a literal ., nothing more.

[^a-z.+3] matches one character that isn't in this list and is the same as [^.a-z3+] or [^+.a-z3]

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download