Since last September decided to re-entry and vocational qualification advanced, began preparing for both exams so far, as well as the current job title application, like a lone wolf, continue to move on the road, now where the total total has been calendar August ...
No regrets, the following is a garden friend needs the regular tool class, directly on the code:
1 Public classRegutils {2 Private StaticLogger Logger = Logger.getlogger (regutils.class. GetName ());3 Private StaticString msg = "";4 Private StaticString regrepspace = "\\s*|\t|\r|\n";5 6 Publicregutils () {7 }8 9 /**Ten * <strong> Delete spaces, line breaks, tab</strong><br> in a string One * <br> A * @authorAARON.FFP - * @versionv1.0.0:autotest-base cn.ffp.autotest.base.util Regutils.java replacespace, 2016-03-03 13:13:00.083 Exp $ - * the * @paramStr - * You need to delete the source string for spaces, line breaks, tab - * - * @returnString + */ - Public Staticstring Replacespace (String str) { + returnRegutils.replace (str, regrepspace, ""); A } at - /** - * <strong> string substitution </strong><br> - * <ul> - * <li> matches by regular expression, the matching part will be replaced </li> - * </ul> in * <br> - * @authorAARON.FFP to * @versionv1.0.0:autotest-base cn.ffp.autotest.base.util Regutils.java Replace, 2016-01-14 00:13:56.657 EXP $ + * - * @paramStr the * The source string to be replaced * * @paramReg $ * Regular expressions that match the part that needs to be replacedPanax Notoginseng * @paramReplacement - * Replace the string after the * @returnString + */ A Public Staticstring Replace (String str, string reg, string replacement) { theString strreplace = ""; + - Try { $Pattern pattern =Pattern.compile (reg); $Matcher Matcher =Pattern.matcher (str); -Strreplace =Matcher.replaceall (replacement); -}Catch(patternsyntaxexception PSE) { themsg = Conserror. Error_illegal_regex +pse.getmessage (); - logger.error (MSG, PSE);Wuyi } the - returnStrreplace; Wu } - About /** $ * <strong> interpret whether a string conforms to a regular expression </strong><br> - * <ul> - * <li> If regular expression is met, return true</li> - * </ul> A * <br> + * @authorAARON.FFP the * @versionv1.0.0:autotest-base cn.ffp.autotest.base.util Regutils.java Reg, 2015-12-27 23:30:35.064 EXP $ - * $ * @paramStr the * Source String the * @paramReg the * Regular Expressions the * @returnBoolean - */ in Public Static Booleanreg (String str, string reg) { the BooleanMatch =false; the About Try { thePattern pattern =Pattern.compile (reg); theMatcher Matcher =Pattern.matcher (str); theMatch =matcher.matches (); +}Catch(patternsyntaxexception PSE) { -msg = Conserror. Error_illegal_regex +pse.getmessage (); the logger.error (MSG, PSE);Bayi } the the returnmatch; - } -}
At this point, Java Learning -049-Tool class successfully completed, I hope this article can give beginners Java you a reference.
Finally, very grateful to the pro-stop, I hope this article can be pro helpful. Warmly welcome the kiss to discuss together and progress together. Thank you so much! ^_^
Java Learning -049-Regular tool class