选择以正则表达式开头的文本行

时间:2011-04-26 17:04:02

标签: regex

我需要一种方法在“h1”之后选择“h1”所有内容,使用正则表达式将其替换为空。我还需要它为@import工作。

我需要改变这个:

    <link href='http://fonts.googleapis.com/css?family=Special+Elite' rel='stylesheet' type='text/css'>
    h1 { font-family: 'Special Elite', arial, serif; }
    @import url(http://fonts.googleapis.com/css?family=Special+Elite);
    <link href='http://fonts.googleapis.com/css?family=Quattrocento+Sans' rel='stylesheet' type='text/css'>
    h1 { font-family: 'Quattrocento Sans', arial, serif; }
    @import url(http://fonts.googleapis.com/css?family=Quattrocento+Sans);
    <link href='http://fonts.googleapis.com/css?family=Smythe' rel='stylesheet' type='text/css'>
    h1 { font-family: 'Smythe', arial, serif; }
    @import url(http://fonts.googleapis.com/css?family=Smythe);

对此:

    <link href='http://fonts.googleapis.com/css?family=Special+Elite' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Quattrocento+Sans' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Smythe' rel='stylesheet' type='text/css'>

1 个答案:

答案 0 :(得分:1)

This one 应与您要保留的行匹配:

(<link.*css'>)

this one 应与您要删除的行匹配:

(h1 {.*})|(@import.*;)