I
I
Igor Fedorov2017-01-11 13:23:41
JavaScript
Igor Fedorov, 2017-01-11 13:23:41

How to replace [ | ] to links (From VK api)?

Good afternoon. There is a string returned by the VK API. How to use regular expression to replace all occurrences
[$1|$2]with<span data-id="$1">$2</span>

Отдельное спасибо [id89083229|Ане], [id169355957|Лере], [id148334713|Маргарите], [id146667775|Насте В.] и [id137626852|Насте Н.], которые согласились сняться в этом видео!

Found /\[((?:club|id)[0-9]+)\|(.+)\]/this regex. But it selects only the first occurrence, and with an error - it affects the next ones.
I will be grateful for help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
ProjectSoft, 2017-01-11
@igor-fedorov

https://regex101.com/r/g2h8KQ/1

K
kpa6uu, 2017-01-11
@kpa6uu

http://www.phpliveregex.com/
Regex: \[(.*)\|(.*)\]
Regex Options: U
Replacement: <span data-id="$1">$2</span>

Отдельное спасибо [id89083229|Ане], [id169355957|Лере], [id148334713|Маргарите], [id146667775|Насте В.] и [id137626852|Насте Н.], которые согласились сняться в этом видео!

=

Отдельное спасибо <span data-id="id89083229">Ане</span>, <span data-id="id169355957">Лере</span>, <span data-id="id148334713">Маргарите</span>, <span data-id="id146667775">Насте В.</span> и <span data-id="id137626852">Насте Н.</span>, которые согласились сняться в этом видео!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question