String Manipulations -data

Good day all I have this alphanumeric value that always starts with COMP and followed by 14 numbers:
image
This is the structure it takes, looking at the first one. I want to only extract from ‘COMP+14 DIGITS’ anything after that should be stripped off.

Hi @Anelisa_Bolosha1

Simply use regex-
Assign Activity
extractedValue =
System.Text.RegularExpressions.Regex.Match(yourString, “COMP\d{14}”).Value

Happy Automation

1 Like

You can use this
System.Text.RegularExpressions.Regex.Match(yourString, “COMP\d{14}”).Value

Alternatively, you can use replace Extra Text :slight_smile:
System.Text.RegularExpressions.Regex.Replace(yourString, “(COMP\d{14}).*”, “$1”)
This will keep only COMP + 14 digits and strips anything after it.

1 Like

Also with these ones I only want to extract the alphanumeric value and exclude the number in the brackets.

That is only extracting from the first letter up until ‘MV’

Try This – ^ [A-Za-z0-9]+_MV
System.Text.RegularExpressions.Regex.Match(yourString, “[1]+_MV”).Value


  1. A-Za-z0-9 ↩︎

Hi @Anelisa_Bolosha1

System.Text.RegularExpressions.Regex.Match(yourString, “[1]+”).Value

This will return:
NPU02425S_MV
VAP20007700_MV
MBFS20000726_MV


  1. A-Z0-9_ ↩︎

COMP is always 4 letters and you always want the next 14 digits. So just use Left(yourVariable,18)

1 Like

This regex should work : COMP\d{14}

I used this:
System.Text.RegularExpressions.Regex.Replace(yourString, “(COMP\d{14}).*”, “$1”)
It worked, thank you

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.