# Regular Expression Examples
import re

print("Example A")
line = "this is a test line"
m = re.search("est", line)
print m
print m.group(0)

print("Example B")
line = "this is a test line"
m = re.search("est|is", line)
print m
print m.group(0)

print("Example C")
line = "this is a test line"
m = re.search("th([ies ]*)", line)
print m
print m.group(0)
print m.group(1), ";"
##print m.group(2)

print("Example D")
line = "this is a test line"
m = re.search("(th)([ies ]*)", line)
print m
print m.group(0)
print m.group(1), ";"
#print m.group(2)


print("Example E")
line = "this is a test line"
m = re.search("[ies ]+", line)
print m
print m.group(0)

print("Example F: Non-greedy +?")
line = "this is a test line"
m = re.search("[ies ]+?", line)
print m
print m.group(0), ";"

print("Example G: Named group")
line = "this this is a test line"
m = re.search("(?P<frst> [a-z]{3}) (?P=frst)", line)
print m
#print m.group(0), ";"

print("Example H: Named group 2")
line = "abcabc is a test line"
m = re.search("(?P<frst>[a-z]{3})(?P=frst)", line)
print m
print m.group(0), ";"

print("Example Hb: Named group 3")
line = "xyzabcabc is a test line"
m = re.search("(?P<frst>[a-z]+)(?P=frst)", line)
print m
print m.group('frst'), ";"

print("Example I: Non-Named group 1 ************************************")
line = "abcabc is a test line"
m = re.search("(?P<pat>[a-z]{2})c(?P=pat)", line)
print m
print m.group(0), ";"
m2 = re.search("([a-z]{2})c\1", line)
print m2
#print m2.group(0),";"


print("Example J: Non-Named group 2")
line = "abDabcab is a test line"
m = re.search("([a-c]+)D\1", line)
print m
#print m.group(0), ";"

print("Example K: Non-Named group 3; example from section 7.1 of Python Tutorial")
line = "the the"
m = re.search("(.+) \1", line)
print m
#print m.group(0), ";"

print("Example L: Look-behind")
m = re.search('(?<=abc)def', 'abcdef')
print m.group(0)


print("Example Raw: Raw patterns")
m = re.search(r"\\", 'ab\\c***def')
print m.group(0)




