1

Could you please help using regexp_extract digits from the following example lines:

  1. 11BARIIOTA0292DEBORAH (space) OLLA (space) JENNY (long-multiple spaces) 0000001242202173171 (space)
  2. 11SBADIOTA0300MICHELLE (space) MARGARETE (long-multiple spaces) 0040170225 (space)
  3. 11NITYIOTA0300SYAHLA (space) RYAN (long-multiple spaces) 613821914423 (space)

Into:

  1. 0000001642202173171
  2. 0040170225
  3. 613821914423

fyi: long-multiple space is around 40-50 spaces

Thank you

3 Answers 3

2

For lines that terminate with 1-or-more spaces, and 'long-multiple-space' is 40-50 spaces.
Here's some different match expressions, depending on your needs...

Match: ^.* {40,50}(\d+) +$
Replace: Group1

Match: ^[A-Z\d]+(?: [A-Z]+){1,2} {40,50}(\d+) +$
Replace: Group1

With regexp_extract, I think the syntax looks more like...
regexp_extract(filename,'^.* {40,50}(\d+) +$', 1)
regexp_extract(filename,'^[A-Z\d]+(?: [A-Z]+){1,2} {40,50}(\d+) +$', 1)

The {1,2} is what matches either 1-or-2 names (like OLLA and JENNY on Line1).
Use {1,9} to match anywhere from 1-9 of those space-separated names.
(same thing with {40,50} for the 'long-multiple-spaces')

Sign up to request clarification or add additional context in comments.

2 Comments

when names with Capitalized then i can add like (?: [a-zA-Z]+) yes?
@Auffan Adding a-z would also match lowercase, but the top expression should suffice. I only included the lower expression incase you needed to be very specific. If needing to be even more specific, you could include include IOTA into the expression, assuming its in all of your strings.
1

Consider below approach

select array_reverse(split(trim(col_name), ' '))[offset(0)]
from your_table         

if applied to sample data in your question - output is

enter image description here

2 Comments

what is offset mean? btw, this works very well ty
0

you can transform your string to simple space separated values then extract numerical values using regexp_extract on top of that resultant string.

select REGEXP_REPLACE(REGEXP_REPLACE("11BARIIOTA0292DEBORAH                  OLLA  JENNY                                                                                             0000001242202173171","  ",""),'[^0-9 ]','');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.