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

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -