我有一个css文件,我想在java.please中使用常规表达式删除所有边距属性(左,右,底部)和填充(左,右)属性帮助我这个
这是我的css
.calibre {
background-color: white;
display: block;
font-family: Times New Roman;
font-size: 1em;
margin-bottom: 0;
margin-left: 20pt;
margin-right: 20pt;
margin-top: 0;
padding-left: 0;
padding-right: 0;
text-align: justify
}
和输出将是这样的
.calibre {
background-color: white;
display: block;
font-family: Times New Roman;
font-size: 1em;
text-align: justify
}
答案 0 :(得分:3)
这对我有用:
String str = ".calibre {"+
" background-color: white;"+
" display: block;"+
" font-family: Times New Roman;"+
" font-size: 1em;"+
" margin-bottom: 0;"+
" margin-left: 20pt;"+
" margin-right: 20pt;"+
" margin-top: 0;"+
" padding-left: 0;"+
" padding-right: 0;"+
" text-align: justify"+
" }";
System.out.println(str.replaceAll("(margin|padding).+?;", ""));
打印出来:
.calibre { background-color: white; display: block; font-family: Times New Roman; font-size: 1em; text-align: justify }