import re
str2='hello: acb cross'
reg = re.compile('hello: (a*) cross')
m = reg.search(str2)
print m
if m:
nat= m.group(0)
print(nat)
In the above snippet i was expecting output to be ‘hello: acb cross’ and if I do group(1) it should have been ‘acb’. But I did not get any. print m returns None. Could anyone please let me know the reason it does not work.
However if I try something like this, it works:
import re
str1 = "carter notes: dependent on stems"
r = re.compile('carter notes:(.*)stems')
m = r.search(str1)
if m:
lx = m.group(1)
#print(m.group(0))
print(lx)
Try this: