0

I wrote a sql query which uses regexp_replace:

SELECT REGEXP_REPLACE (
          '<h1><a href=''https://alove.vn/da nang''>da nang</a>, chung to biet toi da nang</h1>, <a href=''https://alove.vn/da nang''>da nang</a> khong nhung <a href=''https://alove.vn''>trang chu</a> da nang la thanh pho bien',
          '(da nang)',
          '---REPLACE---',
          1,
          0,                                                            -- ALL
          'i')
  FROM DUAL;

And result:

<h1><a href='https://alove.vn/---REPLACE---'>---REPLACE---</a>, chung toi biet toi ---REPLACE---</h1>, <a href='https://alove.vn/---REPLACE---'>---REPLACE---</a> khong nhung <a href='https://alove.vn'>trang chu</a> ---REPLACE--- la thanh pho bien

Please help me expert result, only allow replace word outsite tag h1, and outsite tag a href, outsite tag img alt:

<h1><a href=''https://alove.vn/da nang''>da nang</a>, chung to biet toi da nang</h1>, <a href=''https://alove.vn/da nang''>---REPLACE---</a> khong nhung <a href=''https://alove.vn''>trang chu</a> ---REPLACE--- la thanh pho bien

Thanks

MT0
  • 143,790
  • 11
  • 59
  • 117
hungudgm
  • 9
  • 1
  • 7
  • 1
    Please note, your caps-lock key is broken. – Wernfried Domscheit Jan 10 '17 at 10:37
  • Possible duplicate of [Using regular expressions to parse HTML: why not?](http://stackoverflow.com/questions/590747/using-regular-expressions-to-parse-html-why-not) – Sebas Jan 10 '17 at 10:40
  • Is your input string always XML compliant? If yes, you could use [XQuery](https://docs.oracle.com/cd/B28359_01/appdev.111/b28369/xdb_xquery.htm#CBAGCBGJ) function or [UPDATEXML](https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions205.htm) – Wernfried Domscheit Jan 10 '17 at 10:42

1 Answers1

0

For me this work fine:

SELECT REGEXP_REPLACE( 
'<a href="http://blabla.fr/blibli">Link1</a> more more  <a href="http://blabla.fr/blibli">Link2</a>' 
, '<a(\s[^>]*)?>.*?<\/a>','') 
FROM   dual;

Result:

 more more  
dmotta
  • 1,843
  • 2
  • 21
  • 32