I am trying to create an expression that will give me an output of yes for strings, 6,7,8 and an output of no for 9 & 10. Any advice would be greatly appreciated!
#The regular expression is ' ^<[^<>]*>$ '
print ( 'The regular expression used for 5 strings was "^<[^<>]*>$"' )
string6 = '<an xml tag>'
string7 = '<an xml tag>, </closetag>'
string8 = '<with attribute="77">'
string9 = '<opentag><closetag>'
string10 = '</closetag>'
if re.search( r'^<[^<>]*,>$',string6 ) :
print( "yes" )
else:
print("no")
if re.search( r'^<[^<>]*,>$',string7 ) :
print( "yes" )
else:
print("no")
if re.search(r'^<[^<>]*>$',string8):
print("yes")
else:
print("no")
if re.search(r'^<[^<>]*>$',string9):
print("yes")
else:
print("no")
if re.search(r'^<[^<>]*>$',string10):
print("yes")
else:
print("no")
This is the result: yes no yes no yes
I am trying to get: yes yes yes no no