1

I need an regex, which will match the next urls:

(http|https)://(www)<my domain here>
(http|https)://(www)<my domain here>/page1
(http|https)://(www)<my domain here>/page1/.../
(http|https)://(www)<my domain here>/page1/...?a=b
(http|https)://(www)<my domain here>/page1/...?a=b&c=d...

I have one regex, but I don't know how to edit it

^(http:\/\/|https:\/\/)?(www.)?([a-zA-Z0-9]+).[a-zA-Z0-9]*.[a-z]{3}.?([a-z]+)?$

3 Answers 3

2

You can use the following:

^(http:\/\/|https:\/\/)?(www.)?([a-zA-Z0-9]+).[a-zA-Z0-9]*.[a-z]{3}.?([a-z]+)?(\/[a-z0-9])*(\/?|(\?[a-z0-9]=[a-z0-9](&[a-z0-9]=[a-z0-9]*)?))$

For a specific domain name:

^(http:\/\/|https:\/\/)?(www.)?example\.com(\/?|(\?[a-z0-9]=[a-z0-9](&[a-z0-9]=[a-z0-9]*)?))$

Edit: Validate domain and get Url:

(http:\/\/|https:\/\/)?(www.)?example\.com\S*
Sign up to request clarification or add additional context in comments.

3 Comments

you don't understand me, I want to get only urls with specific domain name, e.g.: example.org... Where I should put "example.org" in your regex?
@Sevak.Avet updated the answer.. i thought you wanted validations for /page1/...?a=b.. etc.. :P
I mean, I want to get full URL with specific domain :) I want to validate only domain, but get full URL
0

Try this:

^https?://[^/@]*\.domain\.com(/.*)?$

Comments

0

Try use this:

^(http|https):\/\/(www).([a-z\.]*)?(\/[a-z1-9\/]*)*\??([\&a-z1-9=]*)?

The explanation I get in site Regular expressions 101.

/^(http|https):\/\/(www).([a-z\.]*)?(\/[a-z1-9\/]*)*\??([\&a-z1-9=]*)?/
    ^ assert position at start of the string
    1st Capturing group (http|https)
        1st Alternative: http
            http matches the characters http literally (case sensitive)
        2nd Alternative: https
            https matches the characters https literally (case sensitive)
    : matches the character : literally
    \/ matches the character / literally
    \/ matches the character / literally
    2nd Capturing group (www)
        www matches the characters www literally (case sensitive)
    . matches any character (except newline)
    3rd Capturing group ([a-z\.]*)?
        Quantifier: ? Between zero and one time, as many times as possible, giving back as needed [greedy]
        [a-z\.]* match a single character present in the list below
        Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
        a-z a single character in the range between a and z (case sensitive)
        \. matches the character . literally
    4th Capturing group (\/[a-z1-9\/]*)*
        Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
       \/ matches the character / literally
        [a-z1-9\/]* match a single character present in the list below
            Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
            a-z a single character in the range between a and z (case sensitive)
            1-9 a single character in the range between 1 and 9
            \/ matches the character / literally
    \?? matches the character ? literally
        Quantifier: ? Between zero and one time, as many times as possible, giving back as needed [greedy]
    5th Capturing group ([\&a-z1-9=]*)?
        Quantifier: ? Between zero and one time, as many times as possible, giving back as needed [greedy]
       [\&a-z1-9=]* match a single character present in the list below
            Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
            \& matches the character & literally
            a-z a single character in the range between a and z (case sensitive)
            1-9 a single character in the range between 1 and 9
            = the literal character =

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.