# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"UNIT OPENER"
test_str = ("NGSS Lesson Outline with Manuscript\n"
"HISTORY \n\n"
"Version Stage Writer/Reviewer Notes Date\n"
"1 Dev Prep1 Maryum Mohsin Script build prep 9-9-16\n"
" \n"
" \n"
" \n\n"
"Contents\n"
"HISTORY 1\n"
"UNIT OVERVIEW 1\n"
"UNIT OPENER 1\n"
"UNIT PROJECT 1\n"
"VOCABULARY 2\n\n"
"UNIT OVERVIEW\n\n"
"CODE TK\n"
"Grade Level 2 \n"
"Unit Title Earth’s Surface\n\n"
"UNIT OPENER\n\n"
"Page Title Unit Opener \n\n"
"Section Part Content\n"
"UnitOpener_1 Habitat Pattern: STATIC – Unit Opener SCREEN VO: Unit 4 Earth’s Su\n"
"rface [RCE Head]: Unit 4 Earth’s Surface Media: Splash: Spec ID# 883V Text [I\n"
"mage Caption]: \n\n"
"UNIT PROJECT \n\n"
"Page Title Unit 4 Project\n\n"
"Section Part Content\n"
"UnitProject_1 Habitat Pattern: STATIC – Intro Unit Project SCREEN VO: Why does\n"
"n’t an ocean freeze completely? Investigate to find out. [RCE Head]: Unit 4 Pro\n"
"ject Text [Head]: Explore Ocean Water Text [Directional Text]: Why does an oce\n"
"an not freeze completely? Investigate to find out. Media: Spec ID# 884P Text [I\n"
"mage Caption]: [icon w/ link to downloadable worksheet] \n\n"
"VOCABULARY\n\n"
"Page Title Unit Review\n\n"
"Section Part Content\n"
"UnitVocabulary_1 Habitat Pattern: INTERACTIVE – TR_Main [RCE head]: Unit 4 Voca\n"
"bulary SCREEN VO: Unit 4 Vocabulary Each card shows a word you will use in thi\n"
"s unit. Choose a card to find out more about the word. Text [Directional Text]:\n"
" Each card shows a word you will use in this unit. Choose a card to find out mo\n"
"re about the word. Media and Options: Voc1: mapVoc2: map titleVoc3: map keyVoc4\n"
": compass rose\n"
" Voc1: Text [label]: map Image1: Spec ID# 900M [simple town map p/u 463M]] Text \n"
"VO: map a drawing or a model of a place Voc2: Text [label]: map title Image2: S\n"
"pec ID# 901M [close up of map title p/u 464M] Text VO: map title part of a map t\n"
"hat tells what the map shows Voc3: Text [label]: map key Image3: Spec ID# 902M\n"
" [close up of map key p/u 464M] Text VO: map key part of a map that shows what t\n"
"he map colors and symbols mean Voc4: Text [label]: compass rose Image4: Spec ID\n"
"# 903M [close up of compass rose p/u 464M] Text VO: compass rose part of a map t\n"
"hat shows the directions north, south, east, and west \n")
matches = re.finditer(regex, test_str)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html