AnsweredAssumed Answered

Using Regular Expression in Calculate Field

Question asked by Matt_C_Smith on Apr 22, 2020
Latest reply on Apr 23, 2020 by bixb0012

Asking for some help on a task I'm dealing with.

 

I have a field (PLAN) with a string that I'd like to split into two separate text fields (PLAN_PFX & PLAN_NUM). Each entry is predictable in the sense that it will be 1-5 alphabetic characters followed by 1-6 numeric characters. Alphabetic characters are always upper-case.

 

So what I need to do is something like...

 

PLANPLAN_PFXPLAN_NUM
A305A305
BTR86542BTR86542
RP808112RP808112
WR8WR8

 

I know I'm going to need to use Regular Expression for it. I've tried a few methods just focusing on calculating for PLAN_NUM initially but I'm just fumbling around in the dark really.

 

PLAN_NUM = regex(!PLAN!)

import re

 

def regex(text):

    split_list = re.split(r'[A-Z]', text)

    return split_list[-1]

But this just returns a blank entry.

 

Any help appreciated. Thanks in advance.

Outcomes