java替换html中的样式

package com.yz.yrh.integration;

import java.util.regex.Pattern;

/**
 * Created by Administrator on 2017/5/12.
 */
public class RegexTest {

    public static void main(String [] args){
        String content="<p align=\"center\">  \t<b><span>耶稣就是答案</span></b>  </p>  <p align=\"center\">  \t<strong>作者:道格·巴契勒\n" +
                "\n" +
                "</strong>  </p>  <p align=\"left\">  \t<br />  </p>  <p align=\"left\">  \tC Em F Dm Am  </p>  <p \n" +
                "\n" +
                "align=\"left\">  \tWhen I gaze up at the countless stars or on an endless sea,  </p>  <p align=\"left\">  \t当我凝视无\n" +
                "\n" +
                "垠的星空和无际的海洋  </p>  <p align=\"left\">  \tE E7 Am D7 G G7  </p>  <p align=\"left\">  \tMy mind may swim \n" +
                "\n" +
                "with questions, bewildering to me,  </p>  <p align=\"left\">  \t无数问号,在我心海里聚集彷徨,  </p>  <p \n" +
                "\n" +
                "align=\"left\">  \tF Dm Em Am F G7 C  </p>  <p align=\"left\">  \tBut then I look into Your book and seek Your face \n" +
                "\n" +
                "in prayer,  </p>  <p align=\"left\">  \t当我打开圣经,在祷告中寻求主面,  </p>  <p align=\"left\">  \tF Dm C Am \n" +
                "\n" +
                "F G7 C C7  </p>  <p align=\"left\">  \tI’m satisfied remembering Your loving grace and care.  </p>  <p \n" +
                "\n" +
                "align=\"left\">  \t祢的慈恩与眷顾,总使我饱足欢畅  </p>  <p align=\"left\">  \t<br />  </p>  <p align=\"left\">  \t\n" +
                "\n" +
                "<b>副歌</b>  </p>  <p align=\"left\">  \tF G7 C Am F G Em  </p>  <p align=\"left\">  \tWhatever questions I may \n" +
                "\n" +
                "have whether great or small,  </p>  <p align=\"left\">  \t尽管心中装满问号,或大或小  </p>  <p align=\"left\">  \tF \n" +
                "\n" +
                "G7 G Em Am  </p>  <p align=\"left\">  \tI know Jesus died to save me, and that He forgave me,  </p>  <p \n" +
                "\n" +
                "align=\"left\">  \t但我知救赎的主、赦我罪,将我恩膏!  </p>  <p align=\"left\">  \tF G7 C A A7 F G7 C  </p>  <p \n" +
                "\n" +
                "align=\"left\">  \tJesus is the answer to it all --- Jesus is the answer to it all.  </p>  <p align=\"left\">  \t耶\n" +
                "\n" +
                "稣是所有疑问的答案 耶稣是所有疑问的答案  </p>  <p align=\"left\">  \tC Em F Dm Am  </p>  <p align=\"left\">  \tI \n" +
                "\n" +
                "have so many questions, I wonder in my heart,  </p>  <p align=\"left\">  \t许许多多的问题 在我心中辗转:  \n" +
                "\n" +
                "</p>  <p align=\"left\">  \tE E7 AM D7 G G7  </p>  <p align=\"left\">  \tHow something comes from nothing? \n" +
                "\n" +
                "When did forever start?  </p>  <p align=\"left\">  \t无中怎能生有? 何处是永恒之源?  </p>  <p align=\"left\">  \t\n" +
                "\n" +
                "F Dm Em F G7 C  </p>  <p align=\"left\">  \tWhy can’t I see Your glory? Where is the Promised Land?  </p>  <p \n" +
                "\n" +
                "align=\"left\">  \t为何祢的荣光我不得见, 哪里有应许的地土山川?  </p>  <p align=\"left\">  \tF Dm C Am F G7 C C7  </p>  \n" +
                "\n" +
                "<p align=\"left\">  \tI’ll trust that You will lead me there if I can take you hand.  </p>  <p align=\"left\">  \t\n" +
                "\n" +
                "我相信只要抓紧祢的手,就必见到主面。  </p>  <p align=\"left\">  \t<br />  </p>  <p align=\"left\">  \t<b>副歌\n" +
                "\n" +
                "</b>  </p>  <p align=\"left\">  \tF G7 C Am F G Em  </p>  <p align=\"left\">  \tWhatever questions I may have \n" +
                "\n" +
                "whether great or small,  </p>  <p align=\"left\">  \t尽管心中装满问号,或大或小  </p>  <p align=\"left\">  \tF \n" +
                "\n" +
                "G7 G Em Am  </p>  <p align=\"left\">  \tI know Jesus died to save me, and that He forgave me,  </p>  <p \n" +
                "\n" +
                "align=\"left\">  \t但我知救赎的主、赦我罪,将我恩膏!  </p>  <p align=\"left\">  \tF G7 C A A7 F G7 C  </p>  <p \n" +
                "\n" +
                "align=\"left\">  \tJesus is the answer to it all --- Jesus is the answer to it all.  </p>  <p align=\"left\">  \t耶\n" +
                "\n" +
                "稣是所有疑问的答案 耶稣是所有疑问的答案!  </p>\n" +
                "<span style=\"color:#E53333;\">我们会定期发布视频和文章,便于手机上网者阅读和收看!</span>";

        //java替换html中的样式
        content=content.replaceAll("[a-zA-Z]*=\".*\""," ");
        System.out.println(content);

    }


}


替换结果如下:


<p  >  	<strong>作者:道格·巴契勒

</strong>  </p>  <p  >  	C Em F Dm Am  </p>  <p 

 >  	当我凝视无

垠的星空和无际的海洋  </p>  <p  >  	My mind may swim 

with questions, bewildering to me,  </p>  <p  >  	无数问号,在我心海里聚集彷徨,  </p>  <p 

 >  	But then I look into Your book and seek Your face 

in prayer,  </p>  <p  >  	F Dm C Am 

F G7 C C7  </p>  <p  >  	I’m satisfied remembering Your loving grace and care.  </p>  <p 

 >  	

<b>副歌</b>  </p>  <p  >  	Whatever questions I may 

have whether great or small,  </p>  <p  >  	F 

G7 G Em Am  </p>  <p  >  	I know Jesus died to save me, and that He forgave me,  </p>  <p 

 >  	F G7 C A A7 F G7 C  </p>  <p 

 >  	耶

稣是所有疑问的答案 耶稣是所有疑问的答案  </p>  <p  >  	I 

have so many questions, I wonder in my heart,  </p>  <p  >  	许许多多的问题 在我心中辗转:  

</p>  <p  >  	How something comes from nothing? 

When did forever start?  </p>  <p  >  	

F Dm Em F G7 C  </p>  <p  >  	Why can’t I see Your glory? Where is the Promised Land?  </p>  <p 

 >  	F Dm C Am F G7 C C7  </p>  

<p  >  	

我相信只要抓紧祢的手,就必见到主面。  </p>  <p  >  	<b>副歌

</b>  </p>  <p  >  	Whatever questions I may have 

whether great or small,  </p>  <p  >  	F 

G7 G Em Am  </p>  <p  >  	I know Jesus died to save me, and that He forgave me,  </p>  <p 

 >  	F G7 C A A7 F G7 C  </p>  <p 

 >  	耶

稣是所有疑问的答案 耶稣是所有疑问的答案!  </p>
<span  >我们会定期发布视频和文章,便于手机上网者阅读和收看!</span>



推荐一个不错的调试正则的网址:http://tool.chinaz.com/regex/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值