Regular expressions

From XPUB & Lens-Based wiki
Revision as of 22:26, 5 December 2013 by Michael Murtaugh (talk | contribs) (Created page with "<source lang="python"> for match in re.findall(r"the \w+", text): print match </source> the use the terms the Project the Baronetage the limited t...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
for match in re.findall(r"the \w+", text):
    print match
   the use
   the terms
   the Project
   the Baronetage
   the limited
   the earliest
   the almost
   the last
   the page
   the favourite
for match in re.findall(r"the (\w+)", text):
    print match
   use
   terms
   Project
   Baronetage
   limited
   earliest
   almost
   last
   page
   favourite


for match in re.findall(r"(\w+) the (\w+)", text):
    print match
   ('for', 'use')
   ('under', 'terms')
   ('of', 'Project')
   ('but', 'Baronetage')
   ('contemplating', 'limited')
   ('of', 'earliest')
   ('over', 'almost')
   ('of', 'last')
   ('was', 'page')
   ('which', 'favourite')