Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

This is the following bytestring 

b'removethis\x00\x002020.10.14\x00\xf2\x00^\n\x84>\x01\x00\x10\x01\x14\x00\x00\x00\x8d\xec\xdc0\x1bo\xe7\x15^\n\x84>\x01\x00\x10\x01\x04\x9b_\x18'

I want everything before my first \x00 removed so my substring remove this gets removed basically.

So the problem is that I only want everything before my first \x00 to get removed not any future \x00's that may come in a string and I'm not sure how to do this.

1 Answer

0 votes
by (36.8k points)

You can build the regex for this.

import re

txt = "b'removethis\x00\x002020.10.14\x00\xf2\x00^\n\x84>\x01\x00\x10\x01\x14\x00\x00\x00\x8d\xec\xdc0\x1bo\xe7\x15^\n\x84>\x01\x00\x10\x01\x04\x9b_\x18'"

x = re.search("\\x00.*", txt)

print(x)

Want to be a master in Data Science? Enroll in this Data Scientist

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...