1

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.

3
  • what is start() for? Commented May 18, 2022 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. Commented May 18, 2022 at 16:59
  • There is no match in the string for your regex pattern so None is returned not a Match object Commented May 18, 2022 at 16:59

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.