KayEss
KayEss

Reputation: 419

Split string, extract and add to another column regex BIGQUERY

I have a table with Equipment column containing strings. I want to split string, take a part of it and add this part to a new column (SerialNumber_Asset). Part of the string i want to extract always has the same pattern: A + 7 digits. Example:

       Equipment                                   SerialNumber_Asset
1      AXION 920 - A2302888 - BG-ADM-82 -NK        A2302888 
    
2      Case IH Puma T4B 220 - BG-AEH-87 - NK       null
    
3      ARION 650 - A7702047 - BG-ADZ-74 - MU       A7702047 
    
4      ARION 650 - A7702039 - BG-ADZ-72 - NK       A7702039 

My code:

select x, y, z,
regexp_extract(Equipment, r'([\A][\d]{7})') as SerialNumber_Asset
FROM `aa.bb.cc`

The message i got:

Cannot parse regular expression: invalid escape sequence: \A

Any suggestions what could be wrong? Thanks

Upvotes: 0

Views: 315

Answers (1)

Yun Zhang
Yun Zhang

Reputation: 5503

Just use A instead of [\A], check example below:

select regexp_extract('AXION 920 - A2302888 - BG-ADM-82 -NK', r'(A[\d]{7})') as SerialNumber_Asset

Upvotes: 1

Related Questions