Python Forum
Regex on more than one line ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regex on more than one line ?
#3
There is what re.VERBOSE is made for splitting up long regex and eg adding comments.
import re

email = re.compile(r"""
    [\w.]+        # match any alphanumeric character or a period
    @             # match the character literally
    \w+\.[a-z]{3} # Any character followed by period and exactly three lower-case letters""", re.VERBOSE)
print(email.findall('[email protected] [email protected]')
Output:
['[email protected]']
The same as.
import re

email = re.compile(r'[\w.]+@\w+\.[a-z]{3}')
print(email.findall('[email protected] [email protected]'))
Output:
['[email protected]']
Reply


Messages In This Thread
Regex on more than one line ? - by JohnnyCoffee - Mar-11-2020, 10:32 PM
RE: Regex on more than one line ? - by micseydel - Mar-11-2020, 11:51 PM
RE: Regex on more than one line ? - by snippsat - Mar-12-2020, 09:33 AM
RE: Regex on more than one line ? - by JohnnyCoffee - Mar-12-2020, 02:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  regex multi-line kucingkembar 6 1,649 Aug-27-2022, 10:27 PM
Last Post: kucingkembar
  [SOLVED] Why does regex fail cleaning line? Winfried 5 2,509 Aug-22-2021, 06:59 PM
Last Post: Winfried
  Regex won't replace character with line break Tomf96 2 2,601 Jan-12-2020, 12:14 PM
Last Post: Tomf96

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020