Matching a group that may or may not exist

前端 未结 5 2595
迷失自我
迷失自我 2021-02-20 03:03

My regex needs to parse an address which looks like this:

BLOOKKOKATU 20 A 773 00810 HELSINKI SUOMI
-------------------- ----- -------- -----
          1                 


        
5条回答
  •  南笙
    南笙 (楼主)
    2021-02-20 03:42

    (.*?)\s(\d{5})\s(\w+)\s(\w*)

    An example:

       SQL> with t as
          2  ( select 'BLOOKKOKATU 20 A 773 00810 HELSINKI SUOMI' text from dual
          3  )
          4  select text
          5       , regexp_replace(text,'(.*?)\s(\d{5})\s(\w+)\s(\w*)','\1**\2**\3**\4') new_text
          6    from t
          7  /
    
    
    TEXT
    -----------------------------------------
    NEW_TEXT
    -----------------------------------------------------------------------------------------
    BLOOKKOKATU 20 A 773 00810 HELSINKI SUOMI
    BLOOKKOKATU 20 A 773**00810**HELSINKI**SUOMI
    
    
    1 row selected.
    

    Regards,
    Rob.

提交回复
热议问题