0

MySQL Version: 8.0

I have a field that has markup-style comments, where double-asterisks in front of and behind text signify that the text between should be bold. What is the proper way to replace all instances of subsequent double-quotes with a different string? If I have a field that looks like this:

The word **bold** should be **bold** in each instance

I need the output to look like this

The word <strong>bold</strong> should be <strong>bold</strong> in each instance

I have tried to use REGEXP_REPLACE, but my regex knowledge is lacking

SET @markup = 'The word **bold** should be **bold** in each instance';

SELECT
REGEXP_REPLACE( @markup, '\*{2}(.*?)\*{2}','<strong>\$1</strong>') AS Markup; 

Which results in the error:

Error Code: 3688. Syntax error in regular expression on line 1, character 1.

Fiddle: https://www.db-fiddle.com/f/7hthXC2n8nYNZoBrRKqR9q/5

2
  • 3
    You need REGEXP_REPLACE( @markup, '\\*{2}(.*?)\\*{2}','<strong>$1</strong>') AS Markup; Commented Nov 21, 2021 at 20:50
  • @WiktorStribiżew That works, thank you. Can you please post that as an answer and I will mark it as solved? Commented Nov 22, 2021 at 0:29

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.