RE: Regex Works on Oro Test Applet but doesn't work in code using oro 2.08

"Kevin Markey" <[email protected]> Tue, 5 Apr 2005 11:04:08 -0600
Newsgroups gmane.comp.jakarta.oro.user
Message-ID <E31E3AC363BEA843BBFD942E20B4D3F00A950B@scswhq.headquarters.silvercreeksystems.com>
Perl5Util.match "Searches for the FIRST pattern match somewhere in a =
String....".  Hence, it would match "AABB12.2453333l3l3lacbblclcl" as =
you have posed it.  If you insist on using this form, insert the Perl =
syntax for beginning and end of string.

Preferable for a number of reasons would be to compile a Pattern (that =
way you can test the validity of the "regexp" String passed into your =
method), precompile your regexes first so you don't need to recompile =
them for every input validation, then to pass the Pattern to a =
PatternMatcher in a PatternMatcher.matches(String,Pattern) method call.  =
This will match the pattern EXACTLY.  The =
PatternMatcher.contains(String,Pattern) method would do what your syntax =
is doing -- just testing whether the pattern is contained SOMEWHERE in =
the input string being validated.

Perl5Util.matcher() does all this, but recompiles the regex into a =
Pattern each time you call it, hence will not give you best performance.

Kevin Markey


-----Original Message-----
From: Keast Ann [mailto:[email protected]]=20
Sent: Tuesday, April 05, 2005 10:18 AM
To: [email protected]
Subject: Regex Works on Oro Test Applet but doesn't work in code using =
oro 2.08=20

I am using jarkarta-oro-2.0.8 to do some input validation.
=20
I have a simple method:=20
=20
import org.apache.oro.text.perl.Perl5Util;

    public static boolean matchRegexp(String value, String regexp) {
        if (regexp =3D=3D null || regexp.length() <=3D 0) {
            return false;
        }
=20
        Perl5Util matcher =3D new Perl5Util();
        return matcher.match("/" + regexp + "/", value);
    }
=20
And it works fine in all cases with the regexp =3D =
(\\d{0,2})(\\.)(\\d{0,4}) except for when value =3D =
0.11000000000000000055511151231257827021181583404541015625
=20
I expected this value to fail because it's greater than 4 digits after =
the decimal point. But it actually passes! =20
=20
It works on the applet at: http://jakarta.apache.org/oro/demo.html ( =
using:  (\d{0,2})(\.)(\d{0,4}) ) but it doesn't work in my code using =
jarkarta-oro-2.0.8.
=20
Any ideas on why this is occuring?
=20
Thanks,
Ann

CONFIDENTIALITY NOTICE: This electronic mail transmission and any =
accompanying documents contain information belonging to Silver Creek =
Systems, Inc. that may be confidential and legally privileged. If you =
are not the intended recipient, any disclosure, copying, distribution or =
action taken in reliance on the information is strictly prohibited. If =
you have received the information in error, please contact the sender by =
reply email and destroy all copies of the original email. Thank You.