как получить начальный текст и конечный текст из пути к изображению в python с помощью регулярного выражения?

Вот данные два сценария

Пример 1

the Image Path is https://ictagrisindh.gov.pk/img/inauguration1.jpg the detail goes here
and the url was this and Click here to view the detail goes here

Пример 2

https://ictagrisindh.gov.pk/img/inauguration1.jpg the detail goes here
Click here to view screenshot the detail goes here

Мой код приведен ниже

import re
 str_text = "the Image Path is https://ictagrisindh.gov.pk/img/inauguration1.jpg the detail goes here and the url was this and Click here to view the detail goes here"
urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', str_text)
print("Urls: ",":".join(urls))

Результат

https://ictagrisindh.gov.pk/img/inauguration1.jpg

я хочу извлечь текст из начальной точки в конечную точку между ними, а также извлечь текст отовсюду в пути изображения

Любая помощь будет оценена и спасибо заранее


person Umair Mubeen    schedule 13.06.2020    source источник
comment
напишите какой-нибудь код, протестируйте его, если он не работает, вернитесь и опубликуйте код и ошибку или что не работает, и я уверен, что люди будут готовы помочь.   -  person Chris Doyle    schedule 13.06.2020
comment
ладно позвольте мне попробовать   -  person Umair Mubeen    schedule 13.06.2020
comment
могу ли я добиться этого, используя регулярное выражение в python?   -  person Umair Mubeen    schedule 13.06.2020
comment
Неясно, что именно вы хотите здесь зафиксировать, возможно, приведите пример того, что вы ищете.   -  person Chris Doyle    schedule 13.06.2020
comment
Крис Дойл проверь это сейчас   -  person Umair Mubeen    schedule 13.06.2020


Ответы (1)


import re

e1 = 'the Image Path is https://ictagrisindh.gov.pk/img/inauguration1.jpg the detail goes here' + \
'and the url was this and Click here to view the detail goes here'

e2 = 'https://ictagrisindh.gov.pk/img/inauguration1.jpg the detail goes here' + \
'Click here to view screenshot the detail goes here'

start_pattern = '(^.+)(?=http.+.jpg)'
image_url_pattern = '(http.+.jpg)'
end_pattern = '(?:^.+.jpg)(.+$)'

start = re.findall(start_pattern, e1)
url = re.findall(image_url_pattern, e1)
end = re.findall(end_pattern, e1)

print(f'start: {start}')
print(f'url: {url}')
print(f'end: {end}')

Пример 1:

start: ['the Image Path is ']
url: ['https://ictagrisindh.gov.pk/img/inauguration1.jpg']
end: [' the detail goes hereand the url was this and Click here to view the detail goes here']

Пример 2:

start: []
url: ['https://ictagrisindh.gov.pk/img/inauguration1.jpg']
end: [' the detail goes hereClick here to view screenshot the detail goes here']
person eNc    schedule 13.06.2020