-1

I have an url like this

<a href="https://www.mysite.com/blog/?attachment_id=638" rel="attachment wp-att-638">

How can i create a regular expression to match the url only and replace that? The regexp should only match where rel has the value attachment, like above.

Anton Gildebrand
  • 3,641
  • 12
  • 50
  • 86
  • 3
    Regex is not a good tool for parsing HTML (http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags). In any case, you need to say what language you are using. – dan1111 Oct 19 '12 at 11:14
  • 1
    you mean the value of href? or certain part of the url? – PyQL Oct 19 '12 at 11:15

1 Answers1

1

try:

/[<]a[^>]+(?:(?:href=["]([^"]+)["][^>]+rel)|(?:rel[^>]+href=["]([^"]+)["]))/

the submatch at index 1 or 2 will contain the url.

simonmenke
  • 2,819
  • 19
  • 28