Regex: need to find the same sequence of characters twice and then wrap the html range around it

On my wiki, I have some source code like the snippet below.

I've made each MySQL statement in bold capital letters with three apostrophes wrapped around it as required by wikimedia.

Now I also want to give each statement the color # 909 as I did with the first statement.

{| class="wikitable"
|-
!style="width:250px" | MySQL Commands
!style="width:500px" | Example 
!Description
|-
|<span style="color:#909">'''SELECT COUNT'''</span>
|'''SELECT COUNT(*)''' '''FROM''' classics;
|'''SELECT COUNT''' displays the number of rows in the table by passing * as a parameter, which means "all rows."
|-
|'''SELECT''' and '''SELECT DISTINCT'''
|'''SELECT''' author '''FROM''' classics; <br>'''SELECT DISTINCT''' author '''FROM''' classics;
|'''SELECT DISTINCT''' (or '''DISTINCTROW''') allows you to "weed out" multiple entries when they contain the same data.
|-
|'''DELETE'''
|'''DELETE FROM''' classics '''WHERE''' title='Little Dorrit';
|This example issues a '''DELETE''' command for all rows whose title column contains the string inside the ‘’. 
|-

      

How can I make a regex that finds a sequence of three apostrophes twice and then put <span style ="color:#909">

before the first group of apostrophes and finally set </span>

after the last group?

+3


source to share


1 answer


Try the following:

(?<!<span style="color:#909">)('''[A-Z\(\)\*\s]+''')(?!</span>) # find
<span style="color:#909">\1</span> # replace

      



Two negative back expressions make the regex match SQL statements that don't already have a tag <span>

. This way you can search and replace as often as you want without ending up with duplicate tags.

This can be done in an editor such as Notepad ++.

+1


source







All Articles