matteo matteo - 1 year ago 69
Python Question

Find text between strings python

I looked at similar question and answers but could not solve my issue.

I have a string, like the following:

ecc, ecc, .....thisIsUnique("92781227-7e7e-4768-8ee3-4e1615bddf3c", ecc, ecc.......


could be very long before and after without having some unique text.

What I need is to get the
92781227-7e7e-4768-8ee3-4e1615bddf3c
code as string. So I'm looking to something that ca sound like:

when you find
thisIsUnique
go ahead, read the code after you find the first
("
characters and keep reading until you find the first
",
characters.

Unfortunately I'm not familiar with regex, but maybe there are different ways to solve the problem

thanks to all

Answer Source

There are a few sites you should read up on for what regex is. https://regexone.com/ and Learning Regular Expressions Use a site like this to test what you have tried: https://regex101.com/ But to get you started, this runs exactly what you have pasted as an example:

import re

text = 'ecc, ecc, .....thisIsUnique("92781227-7e7e-4768-8ee3-4e1615bddf3c", ecc, ecc.......'
match = re.search('thisIsUnique\("([^"]+)', text)
print (match.group(1))

result:

92781227-7e7e-4768-8ee3-4e1615bddf3c
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download