0

i have a problem with my python code. The problem is this line:

match = re.search(pattern, bytes).start()

but i get this error...i hope you can help me.

user187
  • 9
  • 1
  • 2
  • what is start() for? – Metalgear May 18 '22 at 16:59
  • There's no result from `search` so there's nothing to call `start()` on. Impossible to debug further without knowing what `pattern` and `bytes` are. Also, you shouldn't be using `bytes` as a variable name since it's the name of a builtin type. – Samwise May 18 '22 at 16:59
  • There is no match in the string for your regex pattern so `None` is returned not a `Match` object – Iain Shelvington May 18 '22 at 16:59

1 Answers1

1

I think the code should be like the following.

match = re.search(pattern, bytes) 
    
if match != None:        
    print("Match at index %s, %s" % (match.start(), match.end()))        
else: 
    print("The regex pattern does not match.")

Hope it could help.

Metalgear
  • 3,391
  • 1
  • 7
  • 16