开发者

How to use Regular Expression pattern to replace markup with unquoted attributes values

Consider the following markup

<p align=center width='100' height=\"200\" attr=test>aasasd</p>

In order to make this markup valid i want to wrap quotes where they are required.

From the above exmaple i want to apply quotes so the markup will be:

<p align="center" width='100' height="200" attr="test">aasasd</p>

Does anyone know any regex patterns for this purpose?

Im using C#.

EDIT: Looks like i might have to do this another way. Can someone provide me with a Regular Expression to match these v开发者_StackOverflow中文版alues:

align=center 
attr=test

Thanks


Regex is probably not the right approach to this problem. Have a look at tidyfornet which is a .Net wrapper of HTML Tidy, a Java package which generates valid HTML/XHTML from tag soup.


Something like this should work: /=('|\\"|\s*)([\w])*('|\\"|\s*)\b/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜