I
I
Ivan2020-09-10 21:36:49
Python
Ivan, 2020-09-10 21:36:49

Why doesn't it work the way it should?

trans_compile2 = re.compile('[(.+)|(.+)]')
res2 = trans_compile2.findall('[id501053137|Александра]')

I need to select the variables from the brackets between | But elected | , where is the mistake?
['|']

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2020-09-10
@mlneko

Everything just works as it should.
[ ] and | have a special meaning in the regex. If you need exactly such characters, you need to escape them with\
re.compile('\[(.+)\|(.+)\]')

E
Elvis, 2020-09-11
@Dr_Elvis

What a cute smiley...
('[(.+)|(.+)]')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question