Search code examples
python-3.xpython-re

In re module what does \.- do in [\w\.-]+?


I am writing a code to search for all the email addresses. I was wondering why I should write it as: '[\w \.-]+@[\w \.-]+' What does \.- do in [\w\.-]?


Solution

  • [\w.-] matches either a word character (\w), a dash (-) or a dot (.). This is called a character class.