Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this regex:


I run it on the following text: cvc cvcv g f f
You can download RegexBu    ddy at f
" URL with spaces" v

I need to match the following – the bolded text only:

How can I do that?


@slhck your revised regex matches almost everything except when the url starts with www. e.g - " URL with spaces"

I made some changes to the regex to match the leading www. It looks like


Can you please review ? and suggest if there exists better ways of matching it.

share|improve this question
Thanks for improving your question; reopened. But please clarify… why do you need to match and, but not, and not There's no pattern here… – slhck Jul 23 '13 at 18:08
up vote 5 down vote accepted

If you don't want to include the trailing whitespace in a match, use a negative lookahead:


In your example, this would match:

To further match only http or https, and optional www use something like:


Here's John Gruber's regex to check for what looks like an URL, which appears to work quite well in your case:


But honestly, all those approaches will only get you false matches sooner or later. If you need a regular expression to parse URLs, see this Stack Overflow question: What is the best regular expression to check if a string is a valid URL?

share|improve this answer
♦ Hey, I'm stuck with little something, can you see the updated question please? – asadz Jul 23 '13 at 21:36
This is more complicated since you need to check if there's www – I added an example from John Gruber which should work in your case. – slhck Jul 24 '13 at 9:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.