我正在尝试使用GREP / Regex进行搜索和替换
以下是我要搜索的内容
<div align="center" class="orange-arial-11"><b>.+<br>
我想删除<b>, <br>
代码,并将<h3>
标记放在。+找到的地方。
但是我无法得到什么。+在替换时会发现留下来。
例如,我想找到这个
<div align="center" class="orange-arial-11"><b>This is the section I want intact<br>
更改为此
<div align="center" class="orange-arial-11"><h3>This is the section I want intact</h3>
感谢任何帮助。
答案 0 :(得分:3)
使用sed代替grep:
# Modify the file in-place
sed -i~ 's|\(<div align="center" class="orange-arial-11">\)<b>\(.\+\)<br>|\1<h3>\2</h3>|' the-file
答案 1 :(得分:1)
这完全取决于您正在使用的系统,但如果您在括号中添加某些内容,则可以在以后引用它
所以它可能像
s/<b>(.+)<br>/<h3>\1<\/h3>/
答案 2 :(得分:0)
在TextWrangler中:
搜索:
<div align="center" class="orange-arial-11"><b>(.+?)<br>
替换为:
<div align="center" class="orange-arial-11"><h3>\1</h3>
'\ 1'将替换为搜索模式中parens内匹配的字符串。