String Manipulation - Regex

Input String - SCON00005950
Output String - SCON-00005950

There can different scenarios for input string such as SCON00005950, SCON - 00005950, SCON- 00005950 etc. How to make sure output is always in the format i.e., SCON-00000000

Hi @Rohit_Nandwani

Use Below syntax in Assign activity:

inputString = "SCON00005950"

outputString = System.Text.RegularExpressions.Regex.Replace(inputString, "\s*-\s*|\s+", "").Insert(4, "-").PadRight(13, "0"c)

Regards

It does not handle SCON-00005950,

Hi @Rohit_Nandwani

Try this

System.Text.RegularExpressions.Regex.Match(inputString,"[A-Za-z]+").Value+"-"+System.Text.RegularExpressions.Regex.Match(inputString,"[0-9]+").Value

Cheers!!

Hi @Rohit_Nandwani

Can you specify your exact requirement.

Regards

There can be n number of scenarios for input string but output string should always be in format SCON-00000000

Hi @Rohit_Nandwani

Your requirement is whatever may be the input you output must be SCON-00000000 the specified value only.

Regards

Correct. How to achieve that?

@Rohit_Nandwani,

Here is an approach to fulfil your requirement.

strOutput="SCON-"+System.Text.RegularExpressions.Regex.Match(strInput,"\d+").Value

image

image

Sample Code:
RegexWork.xaml (6.9 KB)

Thanks,
Ashok :slight_smile:

Is SCON a fixed value @Rohit_Nandwani

Regards

Yes, but may be lowercase sometimes

1 Like

Hi @Rohit_Nandwani

Since whatever may be your input your output should contain eight zeros I think below syntax should handle all your cases.

inputString = "scon- 00005950"

outputString = System.Text.RegularExpressions.Regex.Match(inputString, "[A-Za-z]+").Value.ToUpper() & "-" & "00000000"

Regards

Hey @Rohit_Nandwani

Welcome back to the forums.

Try this in an Assign activity:
Left:
str_Result

Right:
System.Text.RegularExpressions.Regex.Match(inputString, “(?<=SCON[\s-]*)\d+”, RegexOptions.IgnoreCase).ToString

I have considered the following examples including case sensitivity.
image

Cheers

Steve

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