To replace with a regular expression:
Code fragment:
String documenttxt = entityutils.tostring (Entity, "GBK");//Get Data
Documenttxt=documenttxt.replaceall ("[\\t\\n\\r]", "");//To remove the carriage return line of the content area
Description: The ReplaceAll of the string class has a regular substitution function. \ t is a tab \ n is a newline \ r for carriage return
Java Regular use:
Example method:
Copy Code code as follows:
public void Parsetxt (String content) {
Pattern p = pattern.compile (CONFIG.ARTICLEPTN);
Matcher Matcher = p.matcher (content);
while (Matcher.find ()) {
System.out.println (Matcher.group (1));
}
}
Description: Just remember the pattern class, and its static method Complie parse a regular expression to generate an object.
Then use the model to match the string, get a matcher, and traverse all the matches through the Matcher find method.
Group is the set in the regular expression and the () expression. Group (0) is the original string, Gourp (1) is the first group to match ... That is, the index of the group that is matched starts at 1.