A
A
Alexey Vinogradov2017-10-21 00:25:13
Regular Expressions
Alexey Vinogradov, 2017-10-21 00:25:13

How to set a regular expression to find pieces of text with text?

Hello.
It seems to be simple, but I can't figure out how to do it.
There are many list items <li>текст</li>
. I need to select all chunks that have a phrase in their text, like "a year ago". The text also has other html tags.
Such regular expression (php) /<li.+год\ назад.+<\/li>/Us
takes away from the first <li> до последнего </li>
How to find separate li?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey, 2017-10-21
@andrey004

you need to reduce the pluses of greed by putting questions after them.
.+x -- up to the last character 'x'
.+? -- everything up to the first character 'x'

A
Alexey Vinogradov, 2017-10-23
@alexjc

doesn't work at all. In this example, if you add another one on top, <li>erfgertwertwer</li>then it will be taken. In addition, \w\s will not skip other html tags.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question