去掉小数点后多余的.和0
public static BigDecimal subZeroAndDot ( BigDecimal num) {
String s = num. toString ( ) ;
if ( s. indexOf ( "." ) > 0 ) {
s = s. replaceAll ( "0+?$" , "" ) ;
s = s. replaceAll ( "[.]$" , "" ) ;
return new BigDecimal ( s) ;
}
return num;
}
移除富文本内容中的html标签
public static String getNoImgText ( String inputString) {
if ( inputString == null )
return null ;
String textStr = "" ;
try {
String regEx_script = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>" ;
String regEx_style = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>" ;
String regEx_html = "<[^>]+>" ;
String regEx_special = "\\&[a-zA-Z]{1,10};" ;
String regEx_line = "\\s*|\t|\r|\n|" ;
textStr = getString ( inputString, regEx_script, regEx_style, regEx_html, regEx_special, regEx_line) ;
} catch ( Exception e) {
log. info ( "removeHtmlTag error:{}" , e. getMessage ( ) , e) ;
}
return textStr;
}
private static String getString ( String htmlStr, String . . . args) {
Pattern p_script;
Matcher m_script;
for ( String regEx: args) {
p_script = Pattern . compile ( regEx, Pattern . CASE_INSENSITIVE) ;
m_script = p_script. matcher ( htmlStr) ;
htmlStr = m_script. replaceAll ( "" ) ;
}
return htmlStr;
}
提取富文本内容中的图片地址
public static List < String > getImgStr ( String htmlStr) {
List < String > list = new ArrayList < > ( ) ;
String img = "" ;
Pattern p_image;
Matcher m_image;
String regEx_img = "<img.*src\\s*=\\s*(.*?)[^>]*?>" ;
p_image = Pattern . compile ( regEx_img, Pattern . CASE_INSENSITIVE) ;
m_image = p_image. matcher ( htmlStr) ;
while ( m_image. find ( ) ) {
img = m_image. group ( ) ;
Matcher m = Pattern . compile ( "src\\s*=\\s*\"?(.*?)(\"|>|\\s+)" ) . matcher ( img) ;
while ( m. find ( ) ) {
list. add ( m. group ( 1 ) ) ;
}
}
return list;
}