Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - How to search a large string with no spaces, to see if a value exists

Tags:

python

I have a large string full of byte code so there is no spaces, I am trying to search for a specific part of that code.

For example;

byte_code = 'ergewyegt6t4738t8347tygfhfh47tg4378t58437t485t454gyfofby3gyfg34t5t6435t3465tg3465t4'

The value I am looking for is 'fhfh47tg'.

I have tried the .find String method but did not have much luck. As mentioned before, the string has no spaces.

I'd expect the output to be true once it has found the pattern within the string.

like image 570
Christopher Pantelli Avatar asked Nov 26 '25 18:11

Christopher Pantelli


2 Answers

You can use the in (__contains__) test for substring existence:

if 'fhfh47tg' in byte_code:
    print('Match found')

You can also look at methods like str.find, str.index FWIW.

like image 178
heemayl Avatar answered Nov 29 '25 07:11

heemayl


Using re.search is one option:

if re.search(r'fhfh47tg', byte_code):
    print("MATCH")
else:
    print("NO MATCH")
like image 20
Tim Biegeleisen Avatar answered Nov 29 '25 08:11

Tim Biegeleisen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!