problem in creating a Regular Expression with gnu

Hi All,

iam trying to create a regular expression usinggnu package api..

gnu.regex.RE;

i need to validate the browser's(MSIE) userAgent through my regular expression

userAgent is like :First one ==>Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)

i wrote an regular expression like this:

Mozilla.*(.*)\\s*(.*)compatible;\\s*MSIE(.*)\\s*(.*)([0-9]\\.[0-9])(.*);\\s*(.*)Windows(.*)\\s*NT(.*)\\s*5.0(.*)

Actaully this is validating my userAgent and returns true, my problem is, it is returning true if userAgent is having more words at the end after Windows NT 5.0 like Second One ==>Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) Testing

i want the regularExpression pattern to validate the First one and return true for it, and has to return false for the Second one..

my code is:

import gnu.regexp.*;

import gnu.regexp.REException;

publicclass TestRegexp

{

publicstaticboolean getUserAgentDetails(String userAgent)

{

boolean isvalid =false;

RE regexp =new RE("Mozilla.*(.*)\\s*(.*)compatible;\\s*MSIE(.*)\\s*(.*)([0-9]\\.[0-9])(.*);\\s*(.*)Windows(.*)\\s*NT(.*)\\s*5.0(.*)");

isvalid = regexp.isMatch(userAgent);

return isvalid;

}

publicstaticvoid main(String a[])

{

String userAgent ="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)";

boolean regoutput = getUserAgentDetails(userAgent);

System.out.println("***** regoutput is ****** " + regoutput);

}

}

please help me in solving this..

Thanks in Advance..

thanx,

krishna

[2409 byte] By [krishnachowdarya] at [2007-10-3 2:52:24]
# 1
I think simple string matching should suffice.I don't understand why you use regexp here.
hiwaa at 2007-7-14 20:41:22 > top of Java-index,Java Essentials,Java Programming...
# 2

Ofcourse, i can do comparision with simple string matching..

but problem is the userAgent that i want to support is for all the MSIE versions ranging from 5.0 onwards, so there will the version difference of IE like MSIE 6.0..! or MSIE 5.5 some thing like that..

any ways i will try with StringTokenizer once..!

seems that will do my work..

Thanks,

krishna

krishnachowdarya at 2007-7-14 20:41:22 > top of Java-index,Java Essentials,Java Programming...
# 3
RE regexp = new RE("^Mozilla.*(.*)\\s*(.*?)compatible;\\s*MSIE(.*?)\\s*(.*)([0-9]\\.[0-9])(.*?);\\s*(.*?)Windows(.*?)\\s*NT(.*?)\\s*5.0\\)$");
sabre150a at 2007-7-14 20:41:22 > top of Java-index,Java Essentials,Java Programming...