Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

problem in creating a Regular Expression with gnu

807569Aug 16 2006 — edited Aug 17 2006
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 14 2006
Added on Aug 16 2006
3 comments
162 views