python - need help regarding the following regular expression -
i using python re module regular expressions want remove characters string except numbers , characters. achieve using sub function
code snippet:-
>>> text="foo.bar" >>> re.sub("[^a-z][^a-z]","",text)
'fobar'
i wanted know why above expression removes "o."?
i not able understand why removes "o" can please explain me going on behind this?
i know correct solution of problem
>>> re.sub("[^a-z ^a-z]","",text)
'foobar'
thanks in advance
because o
matches [^a-z]
, .
matches [^a-z]
.
and correct solution [^a-za-z0-9]
.
Comments
Post a Comment