01: package abbot.util;
02:
03: import gnu.regexp.*;
04: import abbot.Log;
05:
06: /** Simple wrapper around the more fully-featured RE class. */
07:
08: public class Regexp {
09: /** Return whether there is a match for the given regular expression
10: * within the given string.
11: */
12: public static boolean stringContainsMatch(String regexp,
13: String actual) {
14: try {
15: boolean multiline = false;
16: if (regexp.startsWith("(?m)")) {
17: multiline = true;
18: regexp = regexp.substring(4);
19: }
20: RE e = new RE(regexp, multiline ? RE.REG_MULTILINE
21: | RE.REG_DOT_NEWLINE : 0);
22: REMatch m = e.getMatch(actual);
23: return m != null;
24: } catch (REException exc) {
25: Log.warn(exc);
26: return false;
27: }
28: }
29:
30: /** Return whether the given regular expression matches the given string
31: * exactly.
32: */
33: public static boolean stringMatch(String regexp, String actual) {
34: if (actual == null)
35: actual = "";
36: try {
37: boolean multiline = false;
38: if (regexp.startsWith("(?m)")) {
39: multiline = true;
40: regexp = regexp.substring(4);
41: }
42: RE e = new RE(regexp, multiline ? RE.REG_MULTILINE
43: | RE.REG_DOT_NEWLINE : 0);
44: return e.isMatch(actual);
45: } catch (REException exc) {
46: Log.warn(exc);
47: return false;
48: }
49: }
50: }
|