Answer the question
In order to leave comments, you need to log in
Excluding an element by regexp
Good afternoon, in the course of digging one parser, a practical question arose.
Here is the regexp: /<strong>\s*(?:<img.*?\/?>)?(.*)<\/strong>/
(?:<img.*?\/?>)
- this part means some image before the text. It may be, it may not be. If the image is missing, the text is parsed normally. But the problem is that if there is an image, it does not end up (?:<img.*?\/?>)
here, but in the block with text (.*)
. How can I fix this regexp?
Parsing object example
<strong><img src="http://www.site.de/images/stories/galleries/reviews/ololo.jpg" alt="ololo" style="margin: 10px; float: left;" height="100" width="100" /> Пока космические корабли бороздят просторы северного ледовитого океана...</strong>
Answer the question
In order to leave comments, you need to log in
In php, everything seems to work as it should:
Maybe it's in flags, such as unicode (?u) or in text wrapping to a new line (?m).
array(2) {
[0]=>
string(301) "<strong><img src="http://www.site.de/images/stories/galleries/reviews/ololo.jpg" alt="ololo" style="margin: 10px; float: left;" height="100" width="100" /> Пока космические корабли бороздят просторы северного ледовитого океана...</strong>"
[1]=>
string(137) " Пока космические корабли бороздят просторы северного ледовитого океана..."
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question