01: package org.sakaibrary.xserver;
02:
03: import java.util.regex.Pattern;
04: import java.util.regex.Matcher;
05:
06: /**
07: * This class is used as a regular expressions utility for XSLT Stylesheets.
08: *
09: * @author gbhatnag
10: *
11: */
12: public class RegexUtility {
13:
14: /**
15: * Tests whether or not the regular expression is contained in the string.
16: *
17: * @param string string to be tested
18: * @param regex regex to be found
19: * @return true if regex is in string, false otherwise
20: */
21: public static boolean test(String string, String regex) {
22: Pattern pattern = Pattern.compile(regex.trim());
23: Matcher matcher = pattern.matcher(string.trim());
24:
25: return matcher.find();
26: }
27:
28: public static boolean startsWith(String string, String regex) {
29: // get the first character
30: String substr = string.substring(0, 1);
31:
32: Pattern pattern = Pattern.compile(regex.trim());
33: Matcher matcher = pattern.matcher(substr);
34:
35: return matcher.find();
36: }
37:
38: public static int strLength(String string) {
39: return string.trim().length();
40: }
41:
42: public static boolean equals(String str1, String str2) {
43: return str1.trim().equals(str2.trim());
44: }
45: }
|