vendredi 27 février 2015

Write a regular expression to capture a substring from html


Vote count:

0




I have to find a particular pattern from html text using regular expression


For example:


my string is



<table border="0" cellspacing="0" cellpadding="0" width="100%"><tbody><tr><td><p align="justify"><u>Counsel appeared</u></p><p align="justify"><a name="COUNSEL" id="COUNSEL"></a>K. P. Garg CA<b>for the Appellant</b>.: A. K. Monga, Sr. DR <b>for theRespondent</b></p><p align="justify"><b><u><a name="JUDGE" id="JUDGE"></a>R. P.TOLANI, JM.</u></b></p><p align="justify">testing</p>..........and so on


and I want to remove a <p align="justify"><u>Counsel appeared</u></p><p align="justify"><a name="COUNSEL" id="COUNSEL"></a>K. P. Garg CA<b>for the Appellant</b>.: A. K. Monga, Sr. DR <b>for theRespondent</b></p> this portion from html text. The text enclosed in the the html tags is dynamic.


For this I have written following regular expression



gsub(/<p align="justify"><u>counsel appeared<\/u><\/p><p align="justify"><a name="counsel" id="counsel"><\/a>.*<b>.*<\/b><\/p>/i, '')


but its removing the whole text from ``counsel appeared</u></p> till end.


So how I remove a particular portion from the above html string? Can anyone help me in modifying my regular expression ?



asked 2 mins ago







Write a regular expression to capture a substring from html

Aucun commentaire:

Enregistrer un commentaire