Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Query to extract HTML tag with data

Nimish GargMay 7 2012 — edited May 8 2012
Hi All,

I have a string.
'<HTML><HEAD>THIS IS HEAD.</HEAD><BODY>THIS IS BODY.<P>THIS IS P1.</P>NIMISH<P>THIS IS P2.</P></BODY></HTML>'

I want to extract a html tag including its opening & closing tab with data as

if i say P1
then the output should be 
'<P>THIS IS P1.</P>'

for P2
then the output should be 
<P>THIS IS P2.</P>

please help me in writing this query with regular expression

i have tried it as following but it is not giving desired result:
WITH T AS
(
SELECT
    '<HTML><HEAD>THIS IS HEAD.</HEAD><BODY>THIS IS BODY.<P>THIS IS P1.</P>NIMISH<P>THIS IS P2.</P></BODY></HTML>' STR
FROM    
    DUAL
)
SELECT REGEXP_SUBSTR(STR, '<P>.+P2.+</P>') FROM T


Thanks & Regards
Nimish Garg
Edited by: Nimish Garg on May 7, 2012 5:49 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 5 2012
Added on May 7 2012
10 comments
7,146 views