Hi All,
iam trying to create a regular expression using
gnu 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;
public class TestRegexp
{
public static boolean 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;
}
public static void 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