Today, the project needs: replace "thyroid nodule 5*3 cm" with "thyroid nodules * cm".
The number in a string to replace the white space.
Code, such as the following:
public static string subString (String str) {string regex = "\\d*"; Pattern p = pattern.compile (regex); Matcher m = p.matcher (str); while (M.find ()) {if (! "". Equals (M.group ())) str = str.replace (M.group (), ""); return str;}
However, it is now assumed that "thyroid nodule 5.1*3.2 cm" is replaced with "thyroid nodule * cm" and then the above-mentioned normal form can not pass.
Due to the number of decimal points, the following is the implementation of the source code. The difference with the above is that the normal form is changed.
public static string subString (String str) {//String regex = "\\d*"; String regex = "[\\d.]"; /Just changed the matching rule Pattern p = pattern.compile (regex); Matcher m = p.matcher (str); while (M.find ()) {if (! "". Equals (M.group ())) str = str.replace (M.group (), ""); return str;}
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Java replacement character or decimal number string