# Only supported 3.10+
# _ is the symbol for wildcard
match value:
case Case1:
...
case Case2:
...
case (5, _): # if value is some tuple with first element 5
...
case _: # you can implement a fall-through like this
...
import re
xx = "guru99,education11 is fun"
r1 = re.findall(r"^w+",xx)
print(r1)
class Point:
x: int
y: int
def where_is(point):
match point:
case Point(x=0, y=0):
print("Origin")
case Point(x=0, y=y):
print(f"Y={y}")
case Point(x=x, y=0):
print(f"X={x}")
case Point():
print("Somewhere else")
case _:
print("Not a point")
# import re module
import re
Substring ='string'
String1 ='''We are learning regex with geeksforgeeks
regex is very useful for string matching.
It is fast too.'''
String2 ='''string We are learning regex with geeksforgeeks
regex is very useful for string matching.
It is fast too.'''
# Use of re.search() Method
print(re.search(Substring, String1, re.IGNORECASE))
# Use of re.match() Method
print(re.match(Substring, String1, re.IGNORECASE))
# Use of re.search() Method
print(re.search(Substring, String2, re.IGNORECASE))
# Use of re.match() Method
print(re.match(Substring, String2, re.IGNORECASE))
>>> match.re
re.compile('(d{3}) (d{2})')
>>> match.string
'39801 356, 2102 1111'