Question
reg_replace in PostgreSql with pattern matching
I have below dataset,
1. '{SHEET,2730377,SHEET,5708283,DATA,3015937}'
2. '{SHEET,2730377,SHEET,5708283,DATA,3015937,DATA,0010965}'
3. '{SHEET,5708283,DATA,3015937,DATA,0010965}'
3. '{SHEET,5708283,DATA,3015937}'
I need the result as,
1. {DATA,3015937}
2. {DATA,3015937,DATA,0010965}
3. {DATA,3015937,DATA,0010965}
4. {DATA,3015937}
Basically I wanted to replace SHEET followed by 7 digit number and extract only DATA followed by 7 digit number.
I tried using regexp_replace('{SHEET,2730377,SHEET,5708283,DATA,3015937}', 'SHEET,(\d\d\d\d\d\d\d),', '' )
the result of this is {SHEET,5708283,DATA,3015937}
, as well as using similar to [0-9][0-9][0-9][0-9][0-9][0-9][0-9]
Finding difficulties to get the accurate result, any suggestion would be appreciated
2 47
2