1

我有一个 wordpress 文件的数据库备份。我需要用 div 替换所有标题。我需要用 div 替换整个标题标签[caption id="dfdsf"]和结束标签[/caption](带大括号)。我怎样才能做到这一点?更换结束标签将很容易。但是寻找开始标签很困难,因为里面可能有任何东西!这个怎么做?

这是一个例子:

[caption id="attachment_34552" align="aligncenter" width="550"]<img class="size-large wp-image-34552" alt="Octopress" src="http://....jpg" width="550" height="385" /> Octopress [/caption]
4

3 回答 3

1

如果你不介意正则表达式,匹配开头的正则表达式是

/\[caption[^]]*\]/

http://rubular.com/r/eRRxYIsVCG

caption如果您要使用andCAPTION等,请记住指定不区分大小写。

如果您只想在命令行上执行此操作,您可以使用sed(1)

sed 's/\[caption[^]]*\]/<div class=\\"sss\\">/g' file.html

它将它发送到标准输入,您可以通过管道传输到您想要的任何文件。

如果要就地修改文件,可以将-i开关添加到sed.

于 2013-07-25T06:10:01.740 回答
0

You can use sed from the terminal in a unix machine.

The command would be like

sed "s/\[caption \([^]]*\)\]/<div \1>/g" youdata.txt > file.txt 
sed "s/\[/caption\]/</div>/g" file.txt > file.txt
于 2013-07-25T06:23:37.440 回答
0

尝试扩展选择命令。它ctrl+shift+m在 Windows 和 Linux 中。我不记得我脑海中的 OS X 绑定。Selection如果您不确定(假设您尚未覆盖它),您可以通过选择菜单来查看它的绑定。将光标放在方括号内的某处。第一个扩展将不包括方括号,但第二个将。

于 2013-07-25T06:10:38.573 回答