Member Avatar for feoperro

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.

Take a look at char class,

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

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

Member Avatar for feoperro

Hi,

Does anyone have a regex pattern for a basic url?

i.e.
http://server:port/url

Thanks again,
Ash.

"://" 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!~*'().;?:
@&=+$,%#-]+)+/*)$
Member Avatar for feoperro

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

adatapost - Thanks, but that doesn't work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.