I know it can denote range, but for example here [-.\d]
seems like this means decimal number. What does dash symbol in front of the regex mean?
Also, why apart from []
, are there ()
around them? What do the ()
mean?
[-.\d]
finds one character that is either ([]
) a dash (-
), a period (.
) or a number (\d
).
The parentheses around mean grouping, so that the matched value can later be accessed using the group()
method of the Match
object.
See also the documentation of the re
module.
The -
doesn't mean anything special here, it is literally matching a dash (probably looking for dash used as a minus sign). The .
is also literal -- it will match a dot (probably used for a decimal point). The \d
will match any number (0-9). If you add a *
or +
multiplier to the end of the example you give it will match any number: positive, negative, or floating point.
The () parentheses that are used mark the start and end of a group and the contents of a group can be retrieved after a match has been performed.
See http://docs.python.org/library/re.html for more information.
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