1

I am looking for a regex-pattern that matches the domain path of an url (http or https)

example 1:

 https://www.blabla.com/path/pic.jpg

should match

 https://www.blabla.com

example 2:

 http://my.domain.tld/directory/?something

should match

 http://my.domain.tld
2
  • 1
    Are you using a programming language (which?) or a tool (which?)? Many languages provide built-in functions to parse URLs. Commented Oct 24, 2012 at 14:35
  • @m.buettner yes i am using actionscript which afaik does not have an URL class but has a RegEx class. Commented Oct 24, 2012 at 14:40

1 Answer 1

2

something along the lines:

#^(https?://[a-z0-9.-]+)(?=/|$).*#i

It depends of course which characters you'd like to allow in the domain name.

P.S. # are there to delimit the regex, i at the end indicates case-insensitivity.

Sign up to request clarification or add additional context in comments.

12 Comments

won't it complain about your /s?
@silentghost Greets! can you explain the - 'function' in the regex? Thanks
@JosephMarikle: that's just to delimit the regex, there was no indication which flavour clamp was using when I posted my answer. Besides, I'm not familiar with details of actionscript regex syntax.
@cl-r: experts-exchange.com ? Not sure I understand your question otherwise.
@cl-r it's a character class (brackets indicate a character class) that includes word characters (\w), periods (.), or dashes(-)
|

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.