在 sublime 中使用正则表达式 cut/paste 行
Using regular expression to cut/paste lines in sublime
使用 sublime 或其他方法将 "data-filter-tags" 移动到上面一行的最佳方法是什么?
<div class="col-4">
<a class="app-list__item">
<div class="display-4" data-filter-tags="angle-down">
<i class="fal fa-angle-down"></i>
</div>
</a>
</div>
<div class="col-4">
<a class="app-list__item">
<div class="display-4" data-filter-tags="angle-left">
<i class="fal fa-angle-left"></i>
</div>
</a>
</div>
结果将如下所示:
<div class="col-4">
<a class="app-list__item" data-filter-tags="angle-down">
<div class="display-4">
<i class="fal fa-angle-down"></i>
</div>
</a>
</div>
<div class="col-4">
<a class="app-list__item" data-filter-tags="angle-left">
<div class="display-4">
<i class="fal fa-angle-left"></i>
</div>
</a>
</div>
代码
(<[^>]*)(>\s*.*?)(\s*data-filter-tags="[^"]*")
替换:</code></p>
<hr>
<h2>结果</h2>
<h3>输入</h3>
<pre><code><div class="col-4">
<a class="app-list__item">
<div class="display-4" data-filter-tags="angle-down">
<i class="fal fa-angle-down"></i>
</div>
</a>
</div>
<div class="col-4">
<a class="app-list__item">
<div class="display-4" data-filter-tags="angle-left">
<i class="fal fa-angle-left"></i>
</div>
</a>
</div>
输出
<div class="col-4">
<a class="app-list__item" data-filter-tags="angle-down">
<div class="display-4">
<i class="fal fa-angle-down"></i>
</div>
</a>
</div>
<div class="col-4">
<a class="app-list__item" data-filter-tags="angle-left">
<div class="display-4">
<i class="fal fa-angle-left"></i>
</div>
</a>
</div>
说明
(<[^>]*)
将以下内容捕获到捕获组 1
<
字面匹配
[^>]*
匹配除 >
之外的任何字符任意次数
(>\s*.*?)
将以下内容捕获到捕获组 2
>
字面匹配
\s*
匹配任意数量的空白字符
.*?
匹配任何字符任意次数,但尽可能少(不包括换行符)
(\s*data-filter-tags="[^"]*")
将以下内容捕获到捕获组 3
\s*
匹配任意数量的空白字符
data-filter-tags="
字面匹配
[^"]*
匹配除 "
之外的任何字符任意次数
"
字面匹配
的替换只是对捕获的文本进行重新排序,使第三个捕获组位于第一个捕获组之后,但在第二个捕获组之前。
使用 sublime 或其他方法将 "data-filter-tags" 移动到上面一行的最佳方法是什么?
<div class="col-4">
<a class="app-list__item">
<div class="display-4" data-filter-tags="angle-down">
<i class="fal fa-angle-down"></i>
</div>
</a>
</div>
<div class="col-4">
<a class="app-list__item">
<div class="display-4" data-filter-tags="angle-left">
<i class="fal fa-angle-left"></i>
</div>
</a>
</div>
结果将如下所示:
<div class="col-4">
<a class="app-list__item" data-filter-tags="angle-down">
<div class="display-4">
<i class="fal fa-angle-down"></i>
</div>
</a>
</div>
<div class="col-4">
<a class="app-list__item" data-filter-tags="angle-left">
<div class="display-4">
<i class="fal fa-angle-left"></i>
</div>
</a>
</div>
代码
(<[^>]*)(>\s*.*?)(\s*data-filter-tags="[^"]*")
替换:</code></p>
<hr>
<h2>结果</h2>
<h3>输入</h3>
<pre><code><div class="col-4">
<a class="app-list__item">
<div class="display-4" data-filter-tags="angle-down">
<i class="fal fa-angle-down"></i>
</div>
</a>
</div>
<div class="col-4">
<a class="app-list__item">
<div class="display-4" data-filter-tags="angle-left">
<i class="fal fa-angle-left"></i>
</div>
</a>
</div>
输出
<div class="col-4">
<a class="app-list__item" data-filter-tags="angle-down">
<div class="display-4">
<i class="fal fa-angle-down"></i>
</div>
</a>
</div>
<div class="col-4">
<a class="app-list__item" data-filter-tags="angle-left">
<div class="display-4">
<i class="fal fa-angle-left"></i>
</div>
</a>
</div>
说明
(<[^>]*)
将以下内容捕获到捕获组 1<
字面匹配[^>]*
匹配除>
之外的任何字符任意次数
(>\s*.*?)
将以下内容捕获到捕获组 2>
字面匹配\s*
匹配任意数量的空白字符.*?
匹配任何字符任意次数,但尽可能少(不包括换行符)
(\s*data-filter-tags="[^"]*")
将以下内容捕获到捕获组 3\s*
匹配任意数量的空白字符data-filter-tags="
字面匹配[^"]*
匹配除"
之外的任何字符任意次数"
字面匹配
的替换只是对捕获的文本进行重新排序,使第三个捕获组位于第一个捕获组之后,但在第二个捕获组之前。