使用 Sublime Text 中的正则表达式将所有 ID 替换为具有特定名称的 Class
Replacing all ID to Class with certain name using regEx in Sublime Text
我有一个巨大的 CSS 文件,我想在 [=13] 中使用正则表达式将所有 ID 选择器 Class 转换为 Class 选择器 =] 文本编辑器中的区域。我正在使用 Sublime Text 3
.
在此文件中,我有一些预期的十六进制颜色,如 #333 and #ff0000
需要考虑,regEx
模式不应跟踪它。
预期结果
查找:
#333 /*do not track*/
#ff0000 /*do not track*/
#item1 /*found*/
#item2 /*found*/
#item3 /*found*/
替换:
#333 /*do not track*/
#ff0000 /*do not track*/
.item1 /*done!*/
.item2 /*done!*/
.item3 /*done!*/
P.S 这个名字可以有也可以没有数字。需要以与上面的十六进制颜色模式不匹配的方式接受字母和数字
达到此目的的最佳正则表达式模式是什么?
提前致谢!
我的猜测是,也许找到,
#(?=item\d)
或
#(?=item)
并替换为 .
。
If you wish to explore/simplify/modify the expression, it's been
explained on the top right panel of
regex101.com. If you'd like, you
can also watch in this
link, how it would match
against some sample inputs.
Demo 2
我有一个巨大的 CSS 文件,我想在 [=13] 中使用正则表达式将所有 ID 选择器 Class 转换为 Class 选择器 =] 文本编辑器中的区域。我正在使用 Sublime Text 3
.
在此文件中,我有一些预期的十六进制颜色,如 #333 and #ff0000
需要考虑,regEx
模式不应跟踪它。
预期结果
查找:
#333 /*do not track*/
#ff0000 /*do not track*/
#item1 /*found*/
#item2 /*found*/
#item3 /*found*/
替换:
#333 /*do not track*/
#ff0000 /*do not track*/
.item1 /*done!*/
.item2 /*done!*/
.item3 /*done!*/
P.S 这个名字可以有也可以没有数字。需要以与上面的十六进制颜色模式不匹配的方式接受字母和数字
达到此目的的最佳正则表达式模式是什么? 提前致谢!
我的猜测是,也许找到,
#(?=item\d)
或
#(?=item)
并替换为 .
。
If you wish to explore/simplify/modify the expression, it's been explained on the top right panel of regex101.com. If you'd like, you can also watch in this link, how it would match against some sample inputs.