Regex VS代码搜索、替换和更改行订单Vuejs
我的标签出现在多个文件中-同一路径但具有不同的图像文件:Regex VS代码搜索、替换和更改行订单Vuejs,regex,vue.js,visual-studio-code,Regex,Vue.js,Visual Studio Code,我的标签出现在多个文件中-同一路径但具有不同的图像文件: <img id="logo" style="margin-left:170px;margin-top:8px;width:85px" class="shrunk" src="~/static/img/poweredby-grey.png" alt=&
<img
id="logo"
style="margin-left:170px;margin-top:8px;width:85px"
class="shrunk"
src="~/static/img/poweredby-grey.png"
alt=" logo"
>
如何调整这两个正则表达式以在整个
标记中搜索和替换-这样,在替换正则表达式中,我可以同时更正行顺序
非常感谢。我想这会对你有所帮助。您可以为不同的属性创建组,然后重新排列它。VS代码的特性与此相结合可能会有所帮助
但是,如果有其他选择,我不建议使用regexp进行这种转换。
最好的方法是使用规则的自动修复选项(如果有)。我怀疑是这个规则给了您一个错误:。在这种情况下,您只需使用--fix
标志运行eslint
,它就会自动重新排序道具。我想这会对您有所帮助。您可以为不同的属性创建组,然后重新排列它。VS代码的特性与此相结合可能会有所帮助
但是,如果有其他选择,我不建议使用regexp进行这种转换。
最好的方法是使用规则的自动修复选项(如果有)。我怀疑是这个规则给了您一个错误:。在这种情况下,您可以简单地使用
--fix
标志运行eslint
,它将自动重新排序道具。一种使正则表达式稍微简单一点的方法是运行两个串联的查找和替换。使用像您这样的扩展可以做到这一点
在您的settings.json中:
"replacerules.rules": {
"editImgSrc": {
"find": "src=\"~/static/img/(.*?)\"",
"replace": ":src=\"require('~/static/' + imgURL + '/$1')\""
},
"reorder vueImgSrc": {
// get the src line and the two preceding lines
"find": "((.*\r?\n){2})( *:src=\"require.*\r?\n)",
"replace": "$3$1" // reorder them
},
},
"replacerules.rulesets": { // bundle the 2 find/replaces into one ruleset
"Replace with vueImgSrc and reorder": {
"rules": [
"editImgSrc",
"reorder vueImgSrc"
]
}
},
{
"key": "alt+w", // whatever keybinding you want
"command": "replacerules.runRuleset",
"when": "editorTextFocus && !editorReadonly",
"args": {
"rulesetName": "Replace with vueImgSrc and reorder"
}
},
然后是一个keybinding来运行它(在keybindings.json中):
让正则表达式稍微简单一点的一种方法是运行两个串联的查找和替换。使用像您这样的扩展可以做到这一点 在您的settings.json中:
"replacerules.rules": {
"editImgSrc": {
"find": "src=\"~/static/img/(.*?)\"",
"replace": ":src=\"require('~/static/' + imgURL + '/$1')\""
},
"reorder vueImgSrc": {
// get the src line and the two preceding lines
"find": "((.*\r?\n){2})( *:src=\"require.*\r?\n)",
"replace": "$3$1" // reorder them
},
},
"replacerules.rulesets": { // bundle the 2 find/replaces into one ruleset
"Replace with vueImgSrc and reorder": {
"rules": [
"editImgSrc",
"reorder vueImgSrc"
]
}
},
{
"key": "alt+w", // whatever keybinding you want
"command": "replacerules.runRuleset",
"when": "editorTextFocus && !editorReadonly",
"args": {
"rulesetName": "Replace with vueImgSrc and reorder"
}
},
然后是一个keybinding来运行它(在keybindings.json中):
将此用作搜索字符串-
(
你能试试这个吗?我相信这些属性的顺序与你在示例中提到的相同….将其用作替换字符串$1$4$3$2$5>
-我测试了它,它似乎有效。让我知道它对你的作用。如果运行良好,那么它会改变行的顺序,下一步你可以运行regex来替换srcUse这是一个搜索字符串-(
你能试试这个吗?我相信这些属性的顺序与你在示例中提到的相同….将其用作替换字符串$1$4$3$2$5>
-我测试了它,它似乎有效。让我知道它对你有何影响。如果运行良好,那么它会改变行的顺序,下一步你可以运行regex来替换src