Quantcast
Channel: Data Preparation & Blending discussions
Viewing all articles
Browse latest Browse all 4999

Regex Expression not behaving as expected/desired

$
0
0

I have been trying to get a Regex expression to work and just can't seem to figure out the correct syntax. Rather than waste more time, I'm opening it up to the Community...

 

Sample Records:

EAG_CAN_2017_Apples1_A

EAG_CAN_2018_Oranges15_B

 

Desired Output:

EAG_CAN_2017_Apples_A

EAG_CAN_2018_Oranges_B

 

Syntax I've tried:

Regex_Replace([Field],"(.*)\d+(.*)","$1"+"$2")

Regex_Replace([Field],"(.*)\d{1,2}(.*)","$1"+"$2")

Regex_Replace([Field],"(.*)\d{1,2}?(.*)","$1"+"$2")

Regex_Replace([Field],"(.*)(\d{1}|(\d{2})(.*)","$1"+"$3")

 

The problem:

It seems that no matter what I try, the "1" in the "15" is captured in the first (.*) expression. I'm particularly surprised that \d{1,2} doesn't work. The Regex help (RegEx Perl Syntax Guide) indicates that this structure matches "between n and m times inclusive"...

 

I'd appreciate any ideas...


Viewing all articles
Browse latest Browse all 4999

Trending Articles