0

match() in following string,

string = "(branch=MAIN).  See the error log at /home/aswamy/run/test_upgrade/2.0-285979.customer_deployment.22499/test.log.2\n"
m = re.match("See the error",string)
print m  ==> (Here m always shows None)

But if I use the same string without any spaces between (branch=MAIN), then match happens as below,

string = "See the error log at /home/kperiyaswamy/runmass/mass_test_upgrade/7.2.0-285979.customer_deployment.22499/infoblox.log.2\n"
m = re.match("See the error",string)
print m ===> (works proper <_sre.SRE_Match object at 0x7fe813825030>)

So if there is a multiple white spaces pattern match doesn't work. Please let me know how to solve above issue

Naggappan Ramukannan
  • 2,564
  • 9
  • 36
  • 59

1 Answers1

1

Its not about the whitespaces.match always starts to match from the beginning of the string.In 2nd case the string is at the start.So you get the match.In first case it isnt so you dont get a match.Use findall if you want to get a match in any case.

vks
  • 67,027
  • 10
  • 91
  • 124