Python Regex Query -


i started learning regex in python. going through code extracting email address string.

str = 'purple alice@google.com, blah monkey bob@abc.com blah dishwasher' emails1 = re.findall(r'[\w\.-]+@[\w\.-]+', str) emails2 = re.findall(r'[\w.-]+@[\w.-]+', str) 

is there difference between code emails1 , emails2? tested on 1 string , both giving same output.

this first post here. please don't mind if post not according standards.thanks.

the difference see . , \., make difference.

. stands "any character except newline" , \. being literal dot. however, in character classes [abcd.] means "any of following" characters . taken literary. since . both in charater class, there no difference between two.

you should escape - in character classes though, since stands character range [a-z]. works in case because it's last character in class, don't want forget @ point , later on wonder "what's going wrong".


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -