4
4
4eloBek2015-08-29 15:32:36
JavaScript
4eloBek, 2015-08-29 15:32:36

How to make replace perform selective replacement?

There are many pieces of text wrapped in span tags . Some of them have a style applied, such as color:red .
Task : add some text after the red text.
For example like this:

// before
<span ... color:red ...> ... </span> ...
// after
<span ... color:red ...> ... </span>(...) ...

How can such a thing be done?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aves, 2015-08-29
@4eloBek

replace(/<span[^>]*color\s*:\s*red[^>]*>.*?<\/span>/gi, '$& (red text)')

X
xmoonlight, 2015-08-29
@xmoonlight

PHP: preg_replace()
JS: replace()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question