#!/usr/bin/env python3
#https://pythex.org/

#'^' means beggiing of string. [^abc] no tokiha no'abc' nanoni ne... hmmm
#$ sign at the end will means expression ends with this. Say "xxx great!$' means looking for the regex ends with great!

import re
beginsWithHelloRegex=re.compile(r'^Hello')

print(beginsWithHelloRegex.search("Hello there!"))

endWithWorldRegex = re.compile(r'world!$')
print(endWithWorldRegex.search('Hello world!'))

# you can specify how it should begin and how it should end

allDigitRegex = re.compile(r'^\d+$')
print(allDigitRegex.search('123456298'))


# dot cHaracter - anything and followed by... for example '.at" means anything end with at. like cat, hat

atRegex = re.compile(r'.at')
b= atRegex.findall('The cat in the hat sat on the flat mat')
print(b)

atRegex2 = re.compile(r'.{1,2}at') # this will show flat
c= atRegex2.findall('The cat in the hat sat on the flat mat')
print(c)


#dot star patter - .* 0 or more


atRegex3 = re.compile(r'.*at') # this will show flat
d= atRegex3.findall('The cat in the hat sat on the flat mat yesterday')
print(d)




nameRegex =re.compile(r'First Name: (.*) Last Name: (.*)')
e=(nameRegex.findall('First Name: Al Last Name: Stewart'))
print(e)

serve = '<To serve human> for dinner.>'

#.* greedy mode,  - .*? non-greedy mode

nongreedy=re.compile(r'<(.*?)>')
f=nongreedy.findall(serve)
print(f)
greedy=re.compile(r'<(.*)>')
g=greedy.findall(serve)
print(g)


#compile include new line:
prime = "Serve the public trust. \nProtect the innocent. \nUpload the low"

#print(prime)

dotStar=re.compile(r'.*')

h=dotStar.search(prime)
print(h)
dotstar2=re.compile(r'.*', re.DOTALL)
i=dotstar2.search(prime)
print(i)




#ignore case - both upper case and lower case will be found

vowelRegex = re.compile(r'[aeiou]',re.I)# IGNORECASEp

j=vowelRegex.findall('Al, why does your programming book blah?')
print(j)
