T
T
Turkmen Time2021-07-11 06:41:36
Python
Turkmen Time, 2021-07-11 06:41:36

How to extract text from another text?

I am making a parser on VPN ShadowSocks.
It is necessary to extract the keys themselves from the messages
. Example:

(Какой-то текст) ss://Y2hhY2hhMjAtaWV0Zi1wb2x5MTMwNTpUZXN0UGFzc3dvcmRAdGVzdC5hZGRyZXNzOjc3Nzc=#TestName (Какой-то текст) 
ss://Y2hhY2hhMjAtaWV0Zi1wb2x5MTMwNTpUZXN0UGFzc3dvcmRAdGVzdC5hZGRyZXNzOjc3Nzc=#TestName (Какой-то текст)


From here you need to pull out all two keys into a list. The keys all start with ss:// and end with #, =, or a space

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2021-07-11
@MrSel

There are at least two ways to solve it:
The first way is to split the lines according to the initial fragment, we get several pieces. We discard the first piece, split the rest along the final fragment and leave the first piece from each - these will be the keys.
The second way is to use regex with the findall method, with a pattern like this:

/(ss:\/\/[a-zA-Z0-9]+=#)/gm
.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question