0

I need a regular expression that identify special links.

I have an array with links, for example this one

array[1] = "http://domain.com/dfdf"
array[2] = "http://domain.com/dfgf"
array[3] = "http://domain2.com/derf"

I want to use a regular expression that extract links from this array under a specific domain (for example domain2)

I'll get an array

array[1] = "http://domain2.com/derf"

I'm looking for the pattern only (I use PHP)

4
  • no, I have the links stored and they are regular, I mean they have the same format "domain.com" Commented Aug 21, 2009 at 10:57
  • What you like to use domain2 or domain2.com as input? should www.domain2.com also be matched by the pattern, what about https : //ssl.domain2.com/something? What about domain2.net? What about links without http in front of them? Commented Aug 21, 2009 at 10:58
  • Regular expressions seem a bit improper for this task. Why not just use the string functions? Commented Aug 21, 2009 at 11:02
  • Are you Abid who's originally from kashmir???? Commented Aug 21, 2009 at 12:29

3 Answers 3

2

This regular expression should do it:

^http://domain2\.com/

And converted into PCRE with / as delimiter:

/^http:\/\/domain2\.com\//

But you can use another character if you want:

~^http://domain2\.com/~
Sign up to request clarification or add additional context in comments.

Comments

0

How about:

(?<!")http://domain2.com[^"]+

Comments

0

This will match https as well as http links:

#^https?://domain2\.com/#

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.