Regular expression Greedy

import re

# Greedy

s = '<html><head><title>Title</title></head></html>'

print(re.match('<.*>', s))
print(re.match('<.*?>', s))

Execution result:

<re.Match object; span=(0, 46), match='<html><head><title>Title</title></head></html>'>
<re.Match object; span=(0, 6), match='<html>'>

Recommended Posts

Regular expression Greedy
Regular expression re
Regular expression in regex.h
Regular expression with pymongo
Date notation regular expression
Regular expression look-ahead, after-yomi
python regular expression memo
Regular expression matching method
Regular expression in Python
Regular expression in Python
Regular expression confirmation quiz!
Python 處 處 regular expression Notes
Julia Quick Note [04] Regular Expression
Regular expression manipulation with Python
Regular expression check tool summary
Decompose hostname with co.jp with regular expression
String replacement with Python regular expression
100 language processing knocks 2020: Chapter 3 (regular expression)
Introduction to regular expression processing system
Start / end match in python regular expression
(Python) HTML reading and regular expression notes
Lambda expression
Search pythondict dictionary key by regular expression
How to write regular expression patterns in Linux
Regular expression symbolic group name in Python / Ruby