首页 > 解决方案 > 打开```后添加语言注释

问题描述

假设这样一个文本

```
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 中应用这样的正则表达式。

标签: regexvim

解决方案


在 vim 中,你可以这样做:

%s/\v(^```)(\_.{-}```)/\1bash\2/g

这就要求

```

是配对的。(与您的 python 子相同)


推荐阅读