Как я могу обернуть текст внутри определенных символов с помощью HTML? [закрыто]Jquery

Программирование на jquery
Гость
Как я могу обернуть текст внутри определенных символов с помощью HTML? [закрыто]

Сообщение Гость »


I have an HTML output that contains hyphen and comma characters.

For example: regular text - bold text, another regular text - another bold text

What I need is to wrap the text after the hyphen with strong tags, up until the comma, and replace the commas with a br tag.

So the output should look like this:

regular text - bold text
another regular text - another bold text
The next code I used replaced the commas with 'br' tags but does not wrap the text after the hyphen with 'strong' tags:
$(document).ready(function() { $('p').each(function() { const text = $(this).text(); const formattedText = text.replace(/- (.*?)(?:\s*,|$)/g, '- $1$2').replace(/,/g, '
'); $(this).html(formattedText); }); });

Источник: https://stackoverflow.com/questions/781 ... -with-html

Вернуться в «Jquery»