Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex VSCode中用于标记的超链接_Regex_Visual Studio Code_Markdown - Fatal编程技术网

Regex VSCode中用于标记的超链接

Regex VSCode中用于标记的超链接,regex,visual-studio-code,markdown,Regex,Visual Studio Code,Markdown,我想将超链接更改为同时标记所有超链接 例如,我有(还有更多) 并且想要: [ask](https://stackoverflow.com/questions/ask) [keyboard-shortcut-in-vscode-for-markdown-links](https://stackoverflow.com/questions/59030873/keyboard-shortcut-in-vscode-for-markdown-links) [ask](https://stackove

我想将超链接更改为同时标记所有超链接

例如,我有(还有更多)

并且想要:

[ask](https://stackoverflow.com/questions/ask)
[keyboard-shortcut-in-vscode-for-markdown-links](https://stackoverflow.com/questions/59030873/keyboard-shortcut-in-vscode-for-markdown-links)  
[ask](https://stackoverflow.com/questions/ask)
[keyboard-shortcut-in-vscode-for-markdown-links](https://stackoverflow.com/questions/59030873/keyboard-shortcut-in-vscode-for-markdown-links)
我已经找到了(对于keybindings.json)

这很有用,但也许任何人都可以添加或给我一个机会来了解我自己:

  • 从链接的最后一部分中选择链接说明,或使用选项卡查看所有链接说明,以便轻松添加说明
  • 仅更改链接(如果链接之间有任何文本)

tia

我认为使用一个代码片段是行不通的(或者我无法理解),因为您要求仅在链接后面有文本时才更改链接。这使得
TM\u选定的\u文本
无法工作。但它可以通过查找和替换非常容易地完成

我编写了一个扩展,可以用来保存find/replace以备将来使用。键绑定示例:

{
    "key": "alt+q",                  // whatever keybinding you want
    "command": "findInCurrentFile",
    "args": {
            // "find": "(^https:.+\\/)(.*$)(\r?\n)(?=(?!https:))",   // if single line of text between links
            "find": "(.+\\/)(.*$)(\r?\n)(?=\\s*(?!https:)[\\s\\S]*^https:)",  // if multiple lines of text
            "replace": "[$2]($1$2)$3",
            "restrictFind": "selections"  // if you want to only find within selections
    },
    "when": "editorTextFocus && editorLangId == 'markdown'"
}

我相信这满足了你的要求,一些文本(我为任何数量的中间文本行)之间的链接。因此,最后一个链接——后面可能有文本——但后面没有链接——不应该被转换


[如果链接之间只有一行文本,正则表达式可以简化很多。]

链接之间可以有多少行文本?
{
    "key": "ctrl+q b",    // Lines 2 Array Only
    "command": "editor.action.insertSnippet",
    "args": {
      "snippet": "${TM_SELECTED_TEXT/(.+)(\\r?(?=\\S))?/[]($1)/g}",
    },
    "when": "editorTextFocus && editorLangId == 'markdown'"
}
{
    "key": "alt+q",                  // whatever keybinding you want
    "command": "findInCurrentFile",
    "args": {
            // "find": "(^https:.+\\/)(.*$)(\r?\n)(?=(?!https:))",   // if single line of text between links
            "find": "(.+\\/)(.*$)(\r?\n)(?=\\s*(?!https:)[\\s\\S]*^https:)",  // if multiple lines of text
            "replace": "[$2]($1$2)$3",
            "restrictFind": "selections"  // if you want to only find within selections
    },
    "when": "editorTextFocus && editorLangId == 'markdown'"
}