正则表达式:需要两次找到相同的字符序列,然后用 html 将其包裹起来
Regex: Need to find the same sequence of characters two times, then wrap a html span around it
在我的 wiki 中,我有一些源代码,例如下面发布的代码片段。
我将每个 MySQL 语句都用粗体大写,按照维基媒体的要求在其周围环绕三个撇号。
我现在也想像对第一个语句所做的那样为每个语句指定颜色 #909。
{| 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 ‘’.
|-
如何做一个正则表达式,找到三个撇号两次的序列,然后将<span style ="color:#909">
放在第一组撇号之前,最后设置一个</span>
在最后一组之后?
试试这个:
(?<!<span style="color:#909">)('''[A-Z\(\)\*\s]+''')(?!</span>) # find
<span style="color:#909"></span> # replace
两个否定环视使得正则表达式只匹配 SQL 还没有 <span>
标记的语句。这样您就可以随心所欲地搜索和替换,而不会出现重复的标签。
这可以在像 Notepad++ 这样的编辑器中完成。
在我的 wiki 中,我有一些源代码,例如下面发布的代码片段。
我将每个 MySQL 语句都用粗体大写,按照维基媒体的要求在其周围环绕三个撇号。
我现在也想像对第一个语句所做的那样为每个语句指定颜色 #909。
{| 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 ‘’.
|-
如何做一个正则表达式,找到三个撇号两次的序列,然后将<span style ="color:#909">
放在第一组撇号之前,最后设置一个</span>
在最后一组之后?
试试这个:
(?<!<span style="color:#909">)('''[A-Z\(\)\*\s]+''')(?!</span>) # find
<span style="color:#909"></span> # replace
两个否定环视使得正则表达式只匹配 SQL 还没有 <span>
标记的语句。这样您就可以随心所欲地搜索和替换,而不会出现重复的标签。
这可以在像 Notepad++ 这样的编辑器中完成。