在VS Code片段中用于给文件名添加连字符的正则表达式

huangapple go评论72阅读模式
英文:

Regex expression for hyphenating file name in a VS Code snippet

问题

我正在尝试为我写的自定义VS Code代码片段创建一个正则表达式。我正在获取以驼峰格式命名的文件名,并修改它,以便在每个单词之间(在大写字母之前)用连字符分隔,然后将整个字符串转换为小写。例如,如果我的文件名为myFileName,结果将是my-file-name。提前感谢您的帮助!

我能够创建在单词之间加入连字符的表达式,使用 ([a-z])([A-Z])/$1-$2/,但我不能确定这是否是最佳方式。在这个表达式之后,我无法将其转换为小写。

英文:

I’m trying to create a regex for a custom VS Code snippet I’m writing. Im taking the file name that’s in camel case format and modifying it so a hyphen separates each word (before the uppercase letter) and then transforms the entire thing to lowercase. For example, if my file name was titled myFileName, the result would be my-file-name. Appreciate the help in advance!

I’m able to create the expression for hyphenating between words with ([a-z])([A-Z])/$1-$2/ but I’m not positive the if that’s the best way to do that. After that expression I’m not able to then transform to lower case

答案1

得分: 1

在 Visual Code 片段中,必须使用 `/downcase` 操作符来将捕获组的值转为小写:
```none
([a-z])([A-Z])/$1-${2:/downcase}/

查看有关片段的 EBNF(扩展巴克斯-瑙尔范式)文档


<details>
<summary>英文:</summary>

In Visual Code snippets, the `/downcase` operator must be used to lowercase a capturing group value:
```none
([a-z])([A-Z])/$1-${2:/downcase}/

See the EBNF (extended Backus-Naur form) for snippets.

huangapple
  • 本文由 发表于 2023年4月7日 01:59:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75952457.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定