I
I
Ivan Goncharenko2016-08-11 17:13:23
PHP
Ivan Goncharenko, 2016-08-11 17:13:23

Regular game: how to convert several adjacent BRs into one?

Line example: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula < br br br br > Lorem ipsum...< br >
Is it possible to convert several standing in a row "< br> < br> < br> < br>" into one, like this - "< br >" ?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir, 2016-08-11
@lutsyi

'< br >< br >< br >Lorem ipsum...< br >'.replace(/(<\s?br\s?>){2,}/g,'< br >')

A
abcd0x00, 2016-08-12
@abcd0x00

>>> import re
>>> 
>>> s = 'abc<br><br><br><br>def<br><br><br><br>ghi'
>>> re.sub(r'(<br>)+', '<br>', s)
'abc<br>def<br>ghi'
>>>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question