D
D
Durilka962021-12-02 20:33:39
Python
Durilka96, 2021-12-02 20:33:39

Regular searches only the beginning of the sentence, what is the reason?

tell me, I made a regular expression, for example "president[a-z]{0,} Georgia[a-z]{0,} '", I search in sentences using the match call,
result=re.match(regular,string, re.I)
but it searches only at the beginning of the line, i.e. displays only sentences starting with this regular expression, but inside the sentence it does not search and does not display, what could be the reason?
output like this

re.Match object; span=(0, 17), match='Президент Грузии '>


program code snippet bufer_news - list, regular - regular, dirt_sentence_block_news_list[dirt_single_sentence] - string (sentence)
result = re.match(regular, dirt_sentence_block_news_list[dirt_single_sentence], re.I)
                    if result!=None:
                        bufer_news.append(result)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-12-02
@Durilka96

searches only at the beginning of a line

The match() method is needed to search at the beginning of a string
https://docs.python.org/3/library/re.html#re.match
will suit youre.search

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question