Search code examples
mysqlsqluuidguid

Strip all dashes in string for GUIDs only


I don't want to replace ALL dashes in a string, but rather replace only those dashes that are part of a GUID/UUID.

Before the replace:

Mary-Anne Smith is a physics professor at the University of Illinois. Her dissertation was focused on the Higgs-Boson particle. Her professor ID is 01140384-5189-11ed-beb7-fa163e98fdf8. You can reach her at mary-annes@ui.edu.

After the replace:

Mary-Anne Smith is a physics professor at the University of Illinois. Her dissertation was focused on the Higgs-Boson particle. Her professor ID is 01140384518911edbeb7fa163e98fdf8. You can reach her at mary-annes@ui.edu.


Solution

  • Try this using Regexp_Replace

    Select Regexp_Replace
    ('string', 
    '[0-9]{8}-[0-9]{4}-[a-z0-9]{4}-[a- 
     z0-9]{12}', '-','') from table;
    

    If we go by the sematics of the data we can also split it on "id is"

    Eg

    Select 
     Replace(Substr(string 
      Instr(String, 
     'Id is' 
      )+1,Instr(String, 
     'Id is' 
      )+1+len(hexIdformat), 
      '-','')
    

    Something like this above.