Regex vscode代码段-转换和替换文件名

Regex vscode代码段-转换和替换文件名,regex,visual-studio-code,vscode-snippets,Regex,Visual Studio Code,Vscode Snippets,我的文件名是 some-fancy-ui.component.html 我想使用vscode片段将其转换为 一些花式的 所以基本上 对每个字符应用大小写 全部替换为_ Remove.component.html 目前我有 “${TM_FILENAME/()()/${1:/upcase}${2://{3:/upcase}/g}” 这给了我这个 'SETUP-PRINTER-SERVER-LIST.COMPONENT.HTML' 这些文档没有解释如何在正则表达式组上结合转换应用replace。如果您

我的文件名是

some-fancy-ui.component.html

我想使用vscode片段将其转换为

一些花式的

所以基本上

  • 对每个字符应用大小写
  • 全部替换为_
  • Remove.component.html
  • 目前我有

    “${TM_FILENAME/()()/${1:/upcase}${2://{3:/upcase}/g}”

    这给了我这个

    'SETUP-PRINTER-SERVER-LIST.COMPONENT.HTML'


    这些文档没有解释如何在正则表达式组上结合转换应用replace。

    如果您需要使用
    -
    分隔块,您可以使用

    "Filename to UPPER_SNAKE_CASE": {
        "prefix": "usc_",
        "body": [
            "${TM_FILENAME/\\.component\\.html$|(^|[-.])([^-.]+)/${1:+_}${2:/upcase}/g}"
        ],
        "description": "Convert filename to UPPER_SNAKE_CASE dropping .component.html at the end"
    }
    
    你可以查一下电话号码

    • \.component\.html$
      -匹配字符串末尾的
      .component.html
    • |
      -或
    • (^ |[-.])
      将字符串的开头或
      -
      /
      捕获到组1中
    • ([^-.]+)
      -
      以外的任何1+字符捕获到组2中
    ${1:+}${2:/upcase}
    替换意味着:

    • ${1:+
      -如果组1不为空
    • \uu
      -替换为
      \u
    • }
      -第一组处理结束
    • ${2:/upcase}
      -将大写的Group 2值放回原处