M
M
Max Yawo2018-06-01 17:59:24
Python
Max Yawo, 2018-06-01 17:59:24

How to find \xNN in a string using python3 regex?

Let's say there is a string '\x3e\x1f\x2c', exactly a string, type str
You need to find \x1f-\x2f in it,
I wrote the expression \\x[1|2]{1}[ in https://pythex.org/ ac|f]{1} and got the result, but python3 doesn't want to process it afterwards.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
planc, 2018-06-01
@planc

why is there a regex if there is a specific string to be found?
Let's say there is a string '\x3e\x1f\x2c', exactly a string, of type str
in that case there is '\\x3e\\x1f\\x2c'

s = r'\x3e\x1f\x2c\x1f-\x2f\x2c\x3c'

print(s)
if s.find('\\x1f-\\x2f') != -1:
    print('совпало')

or
if '\\x1f-\\x2f' in s:
    print('совпало')

https://stackoverflow.com/questions/4901523/whats-...
You need to find \x1f-\x2f
\\x[1|2]{1}[ac|f]{1} in it
\\x (1 or 2 exactly 1 time) (letters from a to c or f exactly 1 time)
that's what he finds with such a regular expression in s = r'\x3e\x1f\x2c\x1f-\x2f\x2c\x3c'
re.findall(r'\\x[1|2]{1}[a-c|f]{1}',s)

['\\x1f', '\\x2c', '\\x1f', '\\x2f', '\\x2c']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question