正则表达式帮助将十六进制代码和 HTML 片段转换为数组和简单列表
Regex help transforming Hexcodes and HTML snippet to Array and and simple list
下面的部分来自 FA cheatsheet, I am trying to convert this to an array and a simple text file using notepad++ to scrape the following FA page as source or direct HTML copy。
首先,我使用了TexFx插件,它与TextFx->Quick选项下的大括号不匹配,我应该尝试哪个。
第二次在 S.O 上使用帮助,我也尝试了 find: ^.*(fa-[^\s]*).*
replace:
但由于复制粘贴到 NP++ from from the fa cheatsheet 以一行结束... ^.
无效。
- 如何转换为 -> 二维数组,因此我需要获取 2 列
<div class="col-md-4 col-sm-6 col-lg-3">
和 <i class="fa fa-bank"></i>
的 CSV
- 如何转换为 -> 每行一个描述的简单文本列表
fa-tumblr-square
fa-bank
...
请帮助我理解正则表达式片段或工具选项,无论哪个有效。
<div class="col-md-4 col-sm-6 col-lg-3">
<i class="fa fa-fw"></i>
fa-tty
<span class="muted">[&#xf1e4;]</span>
</div>
<div class="col-md-4 col-sm-6 col-lg-3">
<i class="fa fa-fw"></i>
fa-tumblr
<span class="muted">[&#xf173;]</span>
</div>
<div class="col-md-4 col-sm-6 col-lg-3">
<i class="fa fa-fw"></i>
fa-tumblr-square
<span class="muted">[&#xf174;]</span>
</div>
编辑 1:
@ShellFish 这是我得到的,它显示在替换中使用正则表达式和我们的换行选项 \(. \)\(fa[^ ]*\)\([^ ]*\)
没有任何匹配我也尝试了 space 和 html 评论......
Div 列表中的正则表达式结果 - 不匹配
正在创建 HTML 列表
awk
您可以通过 awk 使用它。首先将站点内容复制到一个文本文件中。然后执行以下脚本:
BEGIN {
# set record separator to a space, file is split in records
RS = " "
# separate print variables using a double quote
OFS = "\""
}
# if record (string in between spaces) is the word alias
[=10=] ~ "(alias)" {
# skip this line and make sure line number isn't counted
NR = NR - 1
getline
}
# print if the record number is 1, 4, 7 (i.e. a symbol)
NR % 3 == 1 {
print "<div class=", "col-md-4 col-sm-6 col-lg-3", ">"
# contains first field which is the entire record
print " <i class=", "fa fa-fw", ">" "</i>"
}
# print lines 2, 5...
NR % 3 == 2 {
print " "
}
# analogous for lines 3, 6, 9 ...
NR % 3 == 0 {
# sub amp
sub (/&/, "&", )
print " <span class=", "muted", ">" "</span>"
print "</div>\n"
}
注释应该使脚本清晰。您可以按如下方式使用它:
$ awk -f script.awk file
其中 file
是包含网站内容的文件路径,script.awk
包含上述代码。
用法示例:
$ awk -f script.awk file | head -n 11
<div class="col-md-4 col-sm-6 col-lg-3">
<i class="fa fa-fw"></i>
fa-adn
<span class="muted">[&#xf170;]</span>
</div>
<div class="col-md-4 col-sm-6 col-lg-3">
<i class="fa fa-fw"></i>
fa-align-center
<span class="muted">[&#xf037;]</span>
</div>
记事本
首先从文件中删除所有别名,寻找
(alias)
并删除所有匹配项(包括开头的 space)。
在文件中查找以下模式:
(. )(fa[^ ]*)([^ ]*)
这与列表中的一项完全匹配。将其替换为以下字符串:
<div class="col-md-4 col-sm-6 col-lg-3">\r\n<i class="fa fa-fw"></i>\r\n\r\n<span class="muted"></span>\r\n</div>\r\n\r\n
此处 $i
类似于正则表达式中捕获的第 i 个组。组是 (
和 )
之间的正则表达式。如果这不起作用,也许您必须使用 \i
访问组。新的替换字符串变为:
<div class="col-md-4 col-sm-6 col-lg-3">\r\n<i class="fa fa-fw"></i>\r\n\r\n<span class="muted"></span>\r\n</div>\r\n\r\n
- 替换放大器,寻找
&
并替换为 &
正在创建项目列表
可以从复制文件的 html 列表中创建此列表。两次你只需要抓住 (fa[^ ])*
。这可以为单行文件完成,如下所示:
- 再次删除别名(见上文)。
搜索模式:
. (fa[^ ]*)[^ ]*
并替换为 \r\n
或 \r\n
,如果这不起作用。
正在创建 div
行
要创建 div
行,只需匹配 (. fa[^ ]*[^ ]*)
并将其替换为 \r\n
或 \r\n
(如果反斜杠不起作用)。这将在每个 div
条目后放置换行符。
下面的部分来自 FA cheatsheet, I am trying to convert this to an array and a simple text file using notepad++ to scrape the following FA page as source or direct HTML copy。
首先,我使用了TexFx插件,它与TextFx->Quick选项下的大括号不匹配,我应该尝试哪个。
第二次在 S.O 上使用帮助,我也尝试了
find: ^.*(fa-[^\s]*).* replace:
但由于复制粘贴到 NP++ from from the fa cheatsheet 以一行结束...^.
无效。- 如何转换为 -> 二维数组,因此我需要获取 2 列
<div class="col-md-4 col-sm-6 col-lg-3">
和<i class="fa fa-bank"></i>
的 CSV
- 如何转换为 -> 每行一个描述的简单文本列表
fa-tumblr-square fa-bank ...
- 如何转换为 -> 二维数组,因此我需要获取 2 列
请帮助我理解正则表达式片段或工具选项,无论哪个有效。
<div class="col-md-4 col-sm-6 col-lg-3">
<i class="fa fa-fw"></i>
fa-tty
<span class="muted">[&#xf1e4;]</span>
</div>
<div class="col-md-4 col-sm-6 col-lg-3">
<i class="fa fa-fw"></i>
fa-tumblr
<span class="muted">[&#xf173;]</span>
</div>
<div class="col-md-4 col-sm-6 col-lg-3">
<i class="fa fa-fw"></i>
fa-tumblr-square
<span class="muted">[&#xf174;]</span>
</div>
编辑 1:
@ShellFish 这是我得到的,它显示在替换中使用正则表达式和我们的换行选项 \(. \)\(fa[^ ]*\)\([^ ]*\)
没有任何匹配我也尝试了 space 和 html 评论......
正在创建 HTML 列表
awk
您可以通过 awk 使用它。首先将站点内容复制到一个文本文件中。然后执行以下脚本:
BEGIN {
# set record separator to a space, file is split in records
RS = " "
# separate print variables using a double quote
OFS = "\""
}
# if record (string in between spaces) is the word alias
[=10=] ~ "(alias)" {
# skip this line and make sure line number isn't counted
NR = NR - 1
getline
}
# print if the record number is 1, 4, 7 (i.e. a symbol)
NR % 3 == 1 {
print "<div class=", "col-md-4 col-sm-6 col-lg-3", ">"
# contains first field which is the entire record
print " <i class=", "fa fa-fw", ">" "</i>"
}
# print lines 2, 5...
NR % 3 == 2 {
print " "
}
# analogous for lines 3, 6, 9 ...
NR % 3 == 0 {
# sub amp
sub (/&/, "&", )
print " <span class=", "muted", ">" "</span>"
print "</div>\n"
}
注释应该使脚本清晰。您可以按如下方式使用它:
$ awk -f script.awk file
其中 file
是包含网站内容的文件路径,script.awk
包含上述代码。
用法示例:
$ awk -f script.awk file | head -n 11
<div class="col-md-4 col-sm-6 col-lg-3">
<i class="fa fa-fw"></i>
fa-adn
<span class="muted">[&#xf170;]</span>
</div>
<div class="col-md-4 col-sm-6 col-lg-3">
<i class="fa fa-fw"></i>
fa-align-center
<span class="muted">[&#xf037;]</span>
</div>
记事本
首先从文件中删除所有别名,寻找
(alias)
并删除所有匹配项(包括开头的 space)。
在文件中查找以下模式:
(. )(fa[^ ]*)([^ ]*)
这与列表中的一项完全匹配。将其替换为以下字符串:
<div class="col-md-4 col-sm-6 col-lg-3">\r\n<i class="fa fa-fw"></i>\r\n\r\n<span class="muted"></span>\r\n</div>\r\n\r\n
此处
$i
类似于正则表达式中捕获的第 i 个组。组是(
和)
之间的正则表达式。如果这不起作用,也许您必须使用\i
访问组。新的替换字符串变为:<div class="col-md-4 col-sm-6 col-lg-3">\r\n<i class="fa fa-fw"></i>\r\n\r\n<span class="muted"></span>\r\n</div>\r\n\r\n
- 替换放大器,寻找
&
并替换为&
正在创建项目列表
可以从复制文件的 html 列表中创建此列表。两次你只需要抓住 (fa[^ ])*
。这可以为单行文件完成,如下所示:
- 再次删除别名(见上文)。
搜索模式:
. (fa[^ ]*)[^ ]*
并替换为
\r\n
或\r\n
,如果这不起作用。
正在创建 div
行
要创建 div
行,只需匹配 (. fa[^ ]*[^ ]*)
并将其替换为 \r\n
或 \r\n
(如果反斜杠不起作用)。这将在每个 div
条目后放置换行符。