w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Find multiple occurrences of different URLs in a big string, where each URL is between two specific substrings using Python

Try the following:

import re
r1 = re.compile('(?:AAA ")([^"]*)(?:" BBB)')
s = 'AAA "www.example.com" BBB asdf asdf ghgh AAA "www.someurl.com" BBB
gjsltg ajshssl ahssfh AAA "www.anotherurl.com" BBB'
res = r1.findall(s)

You may also consider using finditer() if s is really long.

Updated re looks like this

r1 = re.compile('(?:data-starred-src=")([^"]*)(?:"

but I've simply replaced AAA and BBB with new delimiters so it's possible that the code won't work if it didn't work before.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.