This is a very simple example which ignores lots of very important email-validity edge cases, such as invalid start/end characters and consecutive periods. If there is an alternative solution to a problem, which is simpler and/or does not require the use of regular expressions, please do not use regex just to feel clever.
I really don't recommend using the above expression in your applications; it would be best to instead use a reputable email-validation library or to track down a more complete email validation regex. Regex is great, but it is also one of the least readable programming tools, and one that is very prone to edge cases and bugs.
There are probably dozens of way to format a phone number.
:19|20)\d\b" matches = re.findall(regex, str(html)) # Form a dict of the number of occurrences of each year year_counts = dict((year, matches.count(year)) for year in set(matches)) # Print the dict sorted in descending order for year in sorted(year_counts, key=year_counts.get, reverse=True): print(year, year_counts[year]) . :[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(? Regex matching speeds can range from not-very-fast to extremely slow, depending on how well the expression is written.
This allows us to define each part of the pattern as a capture group. This is fine for most use cases, especially if the text being matched is very short (such as an email address form).
The source code for the examples in this tutorial can be found at the Github repository here - https://github.com/triestpa/You-Should-Learn-Regex We'll start with a very simple example - Match any line that only contains numbers. Regex Option val file = File("test.txt") val content: String = Text() val regex = Regex("^[0-9] $", Regex Option. It may seem tempting to use regular expressions to filter user input (such as from a web form), to prevent hackers from sending malicious commands (such as SQL injections) to your application.