Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
minimal matching in python3
import re
strings = '''
<hajimari>1<kyukei>2<owari>3<saikai>4<owari>
'''
minimal_pattern = r"<hajimari>(.*?)<owari>"
greedy_pattern = r"<hajimari>(.*)<owari>"
minimal_match = re.findall(minimal_pattern, strings)
print(minimal_match)
greedy_match = re.findall(greedy_pattern, strings)
print(greedy_match)
['1<kyukei>2']
['1<kyukei>2<owari>3<saikai>4']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment