How to use REGEXP_REPLACE and replace a partial string

Database
RB
Fan

How to use REGEXP_REPLACE and replace a partial string

How to use REGEXP_REPLACE to search and replace partial strings in Teradata. I want to be able to search a partial string and replace it with space. For example , If my string has 'Walmart and Occurrence >0/Target and Occurrence >0', I want to be able to search just for 'Walmart' and replace the whole string with space. So my output should be '/Target and Occurrence >0'

 

Thanks

RB

Tags (1)
2 REPLIES
Junior Contributor

Re: How to use REGEXP_REPLACE and replace a partial string

This should work:

regexp_replace(x, '[^/]*Walmart[^/]*', ' ',1,0,'i') -- case insensitive
regexp_replace(x, '[^/]*Walmart[^/]*')              -- case sensitive

Check if there's 'Walmart' and then replace everything between the previous slash and the next slash with a space. 

 

RB
Fan

Re: How to use REGEXP_REPLACE and replace a partial string

Thank you Dieter! This is very helpful.