0

I would like to ask about regular expression question. I want to search the following syntax in vs 2008:

<table width="10%" class="test" style=""> </table> 
<table class="test" style="" width="10%">  </table> 
<table class="test" width="10%" style=""> </table> 
<table class="test" width="10%"></table> 
<table class="test"></table> 
<table></table> 
<div width="10%"></div>

I would like to search all width= in the above table text.

The search regular expression

table[^\w]+width="[^"]+"

after search result

<table width="10%" class="test" style=""> </table> 
<table class="test" style="" width="10%">  </table> 
<table class="test" width="10%" style=""> </table> 
<table class="test" width="10%"></table> 

and i want to replace width to style="width:"

The result should be

<table style="width:10%" class="test" style=""> </table> 
<table class="test" style="" style="width:10%">  </table> 
<table class="test" style="width:10%" style=""> </table> 
<table class="test" style="width:10%"></table> 

How can i make this replacement?

  • 2
    Generally, [regex isn't the right tool for parsing HTML](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags). – FThompson Feb 06 '14 at 04:48

1 Answers1

0

Use following regular expression:

width="[^"]+"

[^"] matches any character that is not ".

falsetru
  • 357,413
  • 63
  • 732
  • 636