You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oro-user@jakarta.apache.org by "Train, Peter P" <Tr...@scmb.co.za> on 2000/10/26 09:17:31 UTC

repeated begin string matches using PatternMatcherInput

When doing repeated matches against a PatternMatcherInput, if my match
string includes a begin string indicator (^), only the first match works.
It does not look like the CurrentOffset of the PatternMatcherInput is
considered as the beginning of the string to be matched.  A demonstration
can be found in the example below.  Sample output is provided after the
source code.

1) Is this the expected behaviour or should I report it as a bug?
2) Is it possible to change this behaviour so that I can do repeated matches
involving /^.../?


//Source code
import org.apache.oro.text.regex.*;
import org.apache.oro.text.perl.Perl5Util;

class testregex {
    public static void main (String [] args) {
	Perl5Util matcher = new Perl5Util ();
	String testString = "firstsecond";
	PatternMatcherInput matchInput = new PatternMatcherInput
(testString);
	System.out.println ("current offset is " +
matchInput.getCurrentOffset ());
	System.out.println ("remainder of string from current offset is '" +
			testString.substring (matchInput.getCurrentOffset
()) + "'");
	System.out.println ("about to match /^first/");
	if (matcher.match ("/^first/", matchInput))
	    System.out.println ("found match '" + matcher.group (0) + "'");
	else
	    System.out.println ("failed to match /^first/");

	System.out.println ("current offset is " +
matchInput.getCurrentOffset ());
	System.out.println ("remainder of string from current offset is '" +
			testString.substring (matchInput.getCurrentOffset
()) + "'");
	System.out.println ("about to match /^second/");
	if (matcher.match ("/^second/", matchInput))
	    System.out.println ("found match '" + matcher.group (0) + "'");
	else
	    System.out.println ("failed to match /^second/");
    }
}


sample output:
current offset is 0
remainder of string from current offset is 'firstsecond'
about to match /^first/
found match 'first'
current offset is 5
remainder of string from current offset is 'second'
about to match /^second/
failed to match /^second/





Disclaimer and Confidentiality Note.

Everything in this e-mail and any attachments relating to the
official business of Standard Bank Investment Corporation
is proprietary to the bank. It is confidential, legally privileged
and protected by law. The Bank does not own and endorse 
any other content. Views and opinions are those of the 
sender unless clearly stated as being that of the Bank.

The person addressed in the e-mail is the sole authorised recipient. 
Please notify the sender immediately if it has unintentionally reached 
you and do not read, disclose or use the content in any way.

Stanbic can not assure that the integrity of this communication has been 
maintained nor that it is free of errors, virus, interception or interference.