# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^Plan A:\s+(?<plan_a>[\w\W]+?)\s+Plan B:\s+(?<plan_b>[\w\W]+?)\s+Plan C:\s+(?<plan_c>[\w\W]+)"
test_str = ("Plan A: North Island Exploration\n\n"
"Day 1: Explore Auckland\n"
"- Morning: Visit the Auckland War Memorial Museum\n"
"- Lunch: Try local cuisine at Depot Eatery & Oyster Bar\n"
"- Afternoon: Take a ferry to Waiheke Island for wine tasting\n"
"- Dinner: Dine at The Grove\n"
"- Accommodation: Rydges Auckland\n"
"- Estimated expenses: $150 per person\n"
"- Contingency plan: Visit indoor attractions in case of bad weather\n\n"
"Day 2: Rotorua Adventure\n"
"- Morning: Visit Te Puia and see Pohutu Geyser\n"
"- Lunch: Have a traditional Maori lunch at Tamaki Maori Village\n"
"- Afternoon: Explore Wai-O-Tapu Thermal Wonderland\n"
"- Dinner: Enjoy a dinner cruise on Lake Rotorua\n"
"- Accommodation: Millennium Hotel Rotorua\n"
"- Estimated expenses: $200 per person\n"
"- Contingency plan: Visit a nearby spa for relaxation if outdoor activities are hindered by bad weather\n\n"
"Day 3: Taupo and Tongariro National Park\n"
"- Morning: Take a cruise on Lake Taupo\n"
"- Lunch: Grab a bite at The Brantry\n"
"- Afternoon: Visit Tongariro National Park for hiking\n"
"- Dinner: Dine at Plateau Restaurant\n"
"- Accommodation: Suncourt Hotel & Conference Centre Taupo\n"
"- Estimated expenses: $180 per person\n"
"- Contingency plan: Explore local museums or go shopping in case of bad weather\n\n"
"Day 4: Wellington City Tour\n"
"- Morning: Visit Te Papa Museum\n"
"- Lunch: Try local food at Ortega Fish Shack\n"
"- Afternoon: Explore Wellington Botanic Garden\n"
"- Dinner: Dine at Shed 5\n"
"- Accommodation: QT Wellington\n"
"- Estimated expenses: $160 per person\n"
"- Contingency plan: Visit art galleries or attend cultural performances indoors if outdoor sightseeing is not feasible\n\n"
"Day 5: Return to Auckland\n"
"- Morning: Fly back to Auckland\n"
"- Lunch: Enjoy a meal at The Sugar Club overlooking the city\n"
"- Afternoon: Explore shopping at Queen Street\n"
"- Estimated expenses: $100 per person\n"
"- Contingency plan: Visit indoor markets or shopping centers if outdoor activities are limited\n\n\n"
"Plan B: South Island Adventure\n\n"
"Day 1: Arrival in Queenstown\n"
"- Afternoon: Visit Skyline Queenstown for panoramic views\n"
"- Dinner: Dine at Rata Dining\n"
"- Accommodation: Novotel Queenstown Lakeside\n"
"- Estimated expenses: $150 per person\n"
"- Contingency plan: Explore local wineries or take a scenic drive in case of bad weather\n\n"
"Day 2: Milford Sound\n"
"- Morning: Take a scenic bus tour to Milford Sound\n"
"- Lunch: Have a picnic at the waterfront\n"
"- Afternoon: Cruise through the fjords\n"
"- Dinner: Enjoy seafood at Fergburger\n"
"- Accommodation: Milford Sound Lodge\n"
"- Estimated expenses: $250 per person\n"
"- Contingency plan: Visit local museums or galleries if outdoor activities are not possible\n\n"
"Day 3: Wanaka and Mount Aspiring National Park\n"
"- Morning: Visit Puzzling World in Wanaka\n"
"- Lunch: Dine at Urban Grind Cafe\n"
"- Afternoon: Explore Mount Aspiring National Park\n"
"- Dinner: Enjoy a meal at The Big Fig\n"
"- Accommodation: Edgewater Hotel\n"
"- Estimated expenses: $180 per person\n"
"- Contingency plan: Visit local cafes or bookstores for indoor relaxation if outdoor exploration is hampered by bad weather\n\n"
"Day 4: Glacier Country\n"
"- Morning: Visit Fox Glacier and go hiking\n"
"- Lunch: Grab food at The Last Kitchen\n"
"- Afternoon: Explore Franz Josef Glacier\n"
"- Dinner: Dine at Alice May\n"
"- Accommodation: Scenic Hotel Franz Josef Glacier\n"
"- Estimated expenses: $200 per person\n"
"- Contingency plan: Visit local hot pools or spa for relaxation if outdoor activities are hindered by bad weather\n\n"
"Day 5: Return to Queenstown\n"
"- Morning: Drive back to Queenstown\n"
"- Lunch: Eat at Botswana Butchery\n"
"- Afternoon: Visit Arrowtown for shopping\n"
"- Estimated expenses: $100 per person\n"
"- Contingency plan: Explore local art galleries or attend cultural performances indoors if outdoor activities are limited\n\n\n"
"Plan C: North and South Island Highlights\n\n"
"Day 1: Arrival in Christchurch\n"
"- Afternoon: Visit the Canterbury Museum\n"
"- Dinner: Dine at Pescatore\n"
"- Accommodation: The George Christchurch\n"
"- Estimated expenses: $150 per person\n"
"- Contingency plan: Explore local cafes or bookstores if outdoor activities are hindered by bad weather\n\n"
"Day 2: Arthur's Pass National Park\n"
"- Morning: Take a scenic drive to Arthur's Pass\n"
"- Lunch: Have a meal at the Alpine Restaurant\n"
"- Afternoon: Explore the national park and go hiking\n"
"- Dinner: Enjoy dinner at Devils Punchbowl Cafe\n"
"- Accommodation: Wilderness Lodge Arthur's Pass\n"
"- Estimated expenses: $200 per person\n"
"- Contingency plan: Visit local museums or galleries if outdoor activities are not possible\n\n"
"Day 3: Marlborough Wine Region\n"
"- Morning: Drive to Marlborough region for wine tasting\n"
"- Lunch: Dine at Hans Herzog\n"
"- Afternoon: Visit vineyards for tasting\n"
"- Dinner: Enjoy a meal at Arbour\n"
"- Accommodation: Marlborough Vintners Hotel\n"
"- Estimated expenses: $180 per person\n"
"- Contingency plan: Visit a local market or shop for souvenirs in case of bad weather\n\n"
"Day 4: Abel Tasman National Park\n"
"- Morning: Visit Abel Tasman National Park for kayaking\n"
"- Lunch: Grab a meal at Hooked on Marahau\n"
"- Afternoon: Explore the coastal trails\n"
"- Dinner: Dine at The Park Cafe\n"
"- Accommodation: Parklands Marina Holiday Park\n"
"- Estimated expenses: $220 per person\n"
"- Contingency plan: Visit local spas or hot pools for relaxation if outdoor activities are limited due to bad weather\n\n"
"Day 5: Return to Christchurch\n"
"- Morning: Drive back to Christchurch\n"
"- Lunch: Eat at 27 Steps\n"
"- Afternoon: Explore Christchurch Botanic Gardens\n"
"- Estimated expenses: $100 per person\n"
"- Contingency plan: Visit local art galleries or attend cultural performances indoors if outdoor activities are not feasible.")
matches = re.search(regex, test_str, re.MULTILINE)
if matches:
print ("Match was found at {start}-{end}: {match}".format(start = matches.start(), end = matches.end(), match = matches.group()))
for groupNum in range(0, len(matches.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = matches.start(groupNum), end = matches.end(groupNum), group = matches.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