Hi,

I'm trying to create a single instance of a regex term.

i.e.

boolean rProcessEndpoint = Pattern.matches("[http://]{1,1}", processEndpointInput);
System.out.println(""+processEndpointInput);

However, with this particular instance, you can type "http://http://" and it will return true.

Here is my source of information:
http://www.dreambank.net/regex.html
Here is where I test my regex:
http://www.regular-expressions.info/javascriptexample.html

Thanks,
-Ash.

Edited 7 Years Ago by AshtonHogan: n/a

Take a look at char class,

boolean rProcessEndpoint = Pattern.matches("http://", processEndpointInput);
System.out.println(""+processEndpointInput);
[h]{1,1}[t]{1,1}[t]{1,1}[p]{1,1}

Even with this expression, you can still type "httphttp" and get "true".

"://" you don't get this into account

String processEndpointInput = "http://http://";
        for (int j = 0; j < processEndpointInput.length(); j++) {
            int c = processEndpointInput.charAt(j);
            System.out.println(processEndpointInput.charAt(j) + " hexal code= " + Integer.toHexString(c));
        }
        //  boolean rProcessEndpoint = Pattern.matches("(http...)+", processEndpointInput);
        //  boolean rProcessEndpoint = Pattern.matches("(http[^\\w][^\\w][^\\w])+", processEndpointInput);
        //  boolean rProcessEndpoint = Pattern.matches("(http\\x3a\\x2f\\x2f)+", processEndpointInput);
        //  boolean rProcessEndpoint = Pattern.matches("(http\\x3a\\x2f\\x2f){1,2}", processEndpointInput);
        boolean rProcessEndpoint = Pattern.matches("(http\\:\\/\\/)+", processEndpointInput);
        System.out.println("" + processEndpointInput);
        System.out.println("." + rProcessEndpoint);

with these examples I hope you should do the url excercise by yourself

^(https?://)?(([\w!~*'().&=+$%-]+: )?[\w!~*'().&=+$%-]+@)?(([0-9]{1,3}\.){3}[0-9]{1,3}|([\w!~*'()-]+\.)*
([\w^-][\w-]{0,61})?[\w]\.[a-z]{2,6})(:[0-9]{1,4})?((/*)|(/+[\w!~*'().;?:
@&=+$,%#-]+)+/*)$

I don't really understand what you're saying quuba.

adatapost - Thanks, but that doesn't work.

This article has been dead for over six months. Start a new discussion instead.