regex - 打开```后添加语言注释
问题描述
假设这样一个文本
```
find ~ -regextype posix-extended -iregex '.*/[^/]{3,}.pdf'
```
You should also escape the `.` so that it matches “.” rather than any character:
```
find ~ -regextype posix-extended -iregex '.*/[^/]{3,}\.pdf'
```
The regular expression can be simplified since we only care about three non-“/” characters:
```
find ~ -regextype posix-extended -iregex '.*[^/]{3}\.pdf'
```
我想在开头添加语言注释```
如果带有python,很容易实现
import re
re.sub(r"```([^`]+)```, r```bash\1```, text)
如何在 vim 中应用这样的正则表达式。
解决方案
在 vim 中,你可以这样做:
%s/\v(^```)(\_.{-}```)/\1bash\2/g
这就要求
```
是配对的。(与您的 python 子相同)
推荐阅读
- python - 在 for 循环中使用 if...else 返回一个字符串
- r - 可以有没有任何功能的 R 包吗?
- java - 我正在尝试进行聊天活动,用户可以在其中进行个人聊天。但是有些如何仅从数据库中检索单个数据
- python - 如何从第 x 行开始写入 CSV?
- c# - BasicPublish() 的可靠性如何?
- c - C中的字符置换算法,将输出存储在数组中
- mysql - 如何使用spring应用程序中的键将缓存的mysql数据作为redis缓存中的单个项目读取
- javascript - 如何连接一些函数以获得结果
- javascript - 如何对样式、npm 包或您自己的想法进行分组?
- elasticsearch - Elasticsearch SQL API 中的分页问题