0

Possible Duplicate:
RegEx match open tags except XHTML self-contained tags
How to remove single attribute with quotes via RegEx

I am trying to remove the "sfref" attribute from the html code below:

<a sfref="[Libraries]719c25f9-89b3-4a7c-b6d5-e734b0c06ac1" href="../../HPLC.sflb.ashx">Determination</a> <br />
<img sfref="[Libraries]3e60aebb-acac-4806-bd22-f7986f66e7b3" src="../../Note52011.sflb.ashx">Test</a><br />

So far I have come up with this regex, but it is not matching: (sfref=")([a-zA-Z0-9:;.\s()-\,]*)(")

This is where I am testing if it help: http://regexr.com?2v4h6

Can someone please help me remove the "sfref" attribute?

Community
  • 1
  • 1
TruMan1
  • 33,665
  • 59
  • 184
  • 335
  • 1
    The `
    ` can not hold! (http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454)
    –  Nov 07 '11 at 04:57
  • I thought this looked familiar....you asked pretty much the same question in June... http://stackoverflow.com/questions/6481320/how-to-remove-single-attribute-with-quotes-via-regex/6481332#6481332 – Daniel Haley Nov 07 '11 at 05:05

2 Answers2

1

You really really really shouldn't use regex (see the link in @Jack Maney's comment), but if you have to, this should work:

sfref="[^"]*"
Daniel Haley
  • 51,389
  • 6
  • 69
  • 95
0

This will work for single or double quotes.

sfref=('|").*?\1
phatfingers
  • 9,770
  • 3
  • 30
  • 44