regex - Regular Expression - Get specific group value in SQL -


i have following regular expression problem.

input:

123_321_009 3111_00_001 5123_123 555 666_a66 777_b77_777 

output request below:

123_321 3111_00 5123 555 666_a66 777_b77 

is there way value of output above?

i tried below statement lack idea how value needed.

^(.*?)\\s?([_0-9])?$ 

value appearing after last underscore not needed.

since using oracle, can use regex_replace(val,pattern,'') function pattern.

the following patterns satisfy samples provided:

_[0-9]{3}$

_[0-9]*$

here demonstration of approach using sql*plus:

 scott@dev> tab(num_val)       2    ( select '123_321_009' dual       3    union       4    select '3111_00_001' dual       5    union       6    select '5123_123' dual       7    union       8    select '555' dual       9    )      10  select tab.num_val,      11    regexp_replace(tab.num_val,'_[0-9]{3}$') approach_1,      12    regexp_replace(tab.num_val,'_[0-9]*$') approach_2      13  tab      14  /      num_val     approach_1             approach_2     =========== ====================== ==================     123_321_009 123_321                123_321     3111_00_001 3111_00                3111_00     5123_123    5123                   5123     555         555                    555 

if provided larger sampling (or more specific rule), more specific solution provided.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -