skip to Main Content

I want remove characters between /**/ from a string

example:

convert the string

"select * from food where /* id = 1 and */ food_code = 2"

to

"select * from food where food_code = 2"

2

Answers


  1. It could be done like this

    select regexp_replace('select * from food where /* id = 1 and */ food_code = 2', '/*.+*/', '','g');
    

    Escaping ‘/’ and ‘*’.

    Login or Signup to reply.
  2. We can use a positive lookbehind (?<=re) and positive lookahead (?=re)

    This will capture and remove multiple /.+/

    select regexp_replace(string, '/*(?<=/*)(.*?)(?=*/)*/','', 'g')
    from mytable
    

    Demo here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search