Info on some regular expression

Database
The Teradata Database channel includes discussions around advanced Teradata features such as high-performance parallel database technology, the optimizer, mixed workload management solutions, and other related technologies.
Fan

Info on some regular expression

I have data in a column as :

abc

abcks

dfh 2 dsf

lkhtrh 1 bv 1

vcsvcvc _34

bdchfd 15 sdf,  9

jshfiewhf,_5

as per my requirement, first 3 values are fine. I have modify the others as below(ending digits with or without space , and _ have to be removed):

lkhtrh 1 bv

vcsvcvc

bdchfd 15 sdf

jshfiewhf

can anyone lease help me to write any such regular expression to fit the requirement.

2 REPLIES
Fan

Re: Info on some regular expression

can anyone please provide me some solution on this.

Junior Contributor

Re: Info on some regular expression

This removes all trailing digits, spaces, underscores and commas, regardless of order:

RegExp_Replace(col, '[0-9,_ ]*$', '') -- 'vcsvcvc 3,_34' -> 'vcsvcvc'

And this trailing digits and any optional spaces, underscores and commas before: 

RegExp_Replace(col, '[,_ ]*[0-9]*$', '') -- vcsvcvc '3,_34' -> 'vcsvcvc 3'