If the pattern contains a space followed by a dash then the RE will not match strings with spaces. This may be related to Bug #2121. If you run the code at the end of this description you should get: RE('[\d \-]') did not match ' ' RE('[ \-\d]') did not match ' ' RE('[ \-]') did not match ' ' RE('[ \-]') did not match '123 ' RE('[ \-]') did not match ' 456' RE('[ \-]') did not match '123 456' The following sample code shows the defect: import org.apache.regexp.*; /** * Tests the org.apache.regexp.RE class * * @author <a href="mailto:dwhelan@innovasys.com">Declan Whelan</a> * @version <!--$$Revision: 1.2 $--> */ public class RETest { /** * Runs the test suite. * * @param theArgs */ public static void main(String theArgs[]) { try { // all the below should match a space or a dash String[] patterns = { "[\\d\\- ]", "[\\d \\-]", "[ \\d\\-]", "[ \\-\\d]", "[\\- \\d]", "[\\-\\d ]", "[ ]", "[ \\-]", "[\\- ]"}; String[] matchedStrings = {" ", "123 ", " 456", "123 456"}; for (int i=0; i < patterns.length; i++) { RE re = new RE(patterns[i]); for (int j=0; j < matchedStrings.length; j++) { if (!re.match(matchedStrings[j])) { System.err.println("RE('" + patterns[i] + "') did not match '" + matchedStrings[j] + "'"); } } } } catch(RESyntaxException x) { System.err.println(x.getMessage()); } } }
*** This bug has been marked as a duplicate of 19329 ***
Fixed by Bug #19329