Bug 5212

Summary: Bracketed space [ \-] followed by dash does not match space
Product: Regexp Reporter: Declan Whelan <dwhelan>
Component: OtherAssignee: Jakarta Notifications Mailing List <notifications>
Status: CLOSED DUPLICATE    
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: Other   
OS: other   

Description Declan Whelan 2001-11-30 11:29:38 UTC
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());
		}
	}
}
Comment 1 Vadim Gritsenko 2003-04-25 17:59:08 UTC

*** This bug has been marked as a duplicate of 19329 ***
Comment 2 Vadim Gritsenko 2003-05-02 01:10:02 UTC
Fixed by Bug #19329