获取特定字符之间的文本

时间:2014-07-30 14:46:44

标签: regex notepad++

我有一些如下代码。

<table class="formulaTablePopular">
    <tr>
        <td class="forma">
            <input type="hidden" value="0" id="F01"/>
            <div class="formulaOk" id="F01Div"
                 onclick="toggleFormulu(this, 'F01');"
                 onmouseover="toggleFormuluOver(this);"
                 onmouseout="toggleFormuluOut(this);">
            </div>
        </td>
        <td class="slika">
            $$ a^3 + b^3 = (a+b)\left(a^2 - ab + b^2\right) $$
        </td>
    </tr>    
</table>

<table class="formulaTablePopular">
    <tr>
        <td class="forma">
            <input type="hidden" value="0" id="F02"/>
            <div class="formulaOk" id="F02Div"
                 onclick="toggleFormulu(this, 'F02');"
                 onmouseover="toggleFormuluOver(this);"
                 onmouseout="toggleFormuluOut(this);">
            </div>
        </td>
        <td class="slika">
            $$ a^3 - b^3 = (a-b)\left(a^2 + ab + b^2\right) $$
        </td>
    </tr>    
</table>

<table class="formulaTablePopular">
    <tr>
        <td class="forma">
            <input type="hidden" value="0" id="F03"/>
            <div class="formulaOk" id="F03Div"
                 onclick="toggleFormulu(this, 'F03');"
                 onmouseover="toggleFormuluOver(this);"
                 onmouseout="toggleFormuluOut(this);">
            </div>
        </td>
        <td class="slika">
            $$ a^2 - b^2 = (a-b)(a+b) $$
        </td>
    </tr>    
</table>

我怎样才能在$$字符之间获取所有文字? 我需要删除除这些代码之外的所有文本

$$ a^3 + b^3 = (a+b)\left(a^2 - ab + b^2\right) $$
$$ a^3 - b^3 = (a-b)\left(a^2 + ab + b^2\right) $$
$$ a^2 - b^2 = (a-b)(a+b) $$

可以在notepad ++中执行此操作吗?

2 个答案:

答案 0 :(得分:5)

找到:

^.*$(?<!\$\$)

并且一无所获。确保您已取消选中&#34; .匹配换行符&#34;选项。

说明:

^        # assert position at the beginning of the line
.*       # matches as much text (except newlines) as possible
$        # assert position at the end of the line
(?<!     # a negative lookbehind: looks behind to see if there is '$$', 
         # and if not, causes the pattern to fail
  \$\$   # match '$$' literally
)        # end of lookbehind

答案 1 :(得分:4)

您可以使用以下内容,这将删除除这些模式之外的所有内容。

Find: [^$]*(\${2}[^$]+\${2})[^$]*
Replace: \1\n

Live Demo