如何在 Vim 中编写这个 perl regex 替换命令? (摘自this pandoc epub tutorial):
perl -i -0pe \
's/^Insert\s*(.*)\.png\s*\n([^\n]*)$/!\[\2](..\/figures\/\1-tn.png)/mg' \
*/*.markdown
最佳答案
我不能代表 -i -0pe
标志,但正则表达式:
s/^Insert\s*(.*)\.png\s*\n([^\n]*)$/!\[\2](..\/figures\/\1-tn.png)/mg
将是:
s/^Insert\s*\(.*\).png\s*\n\(.*\)$/!\[\2](..\/figures\/\1-tn.png)/g
请注意,您必须转义捕获组,并且我在第二个捕获组中使用了 .*
而不是 [^\n]*
。您不需要多行标志。
关于regex - Vim 中的 Perl 正则表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9178486/