Extract all order numbers from the input text

Regex we are using: \b(?=[A-Za-z]\d)(?=\d[A-Za-z])[A-Za-z0-9]{10}\b

Requirement for Order ID: Order ID consists of 10 digits and starts with “S”

Expected Output:
S123456789
S153375999
S153375000

Input text: → String format

BAN MSISDN Order ID IMEI
972856857 7067059409 S123456789 Lghhjkjkb8999
972856757 7069656941 S153375999 Lghhjkjkb8999
972856757 7069656941 S153375000 Lghhjkjkb8999

@anjali123

Try with this regex: S\d{9}

S - Matches the letter “S”.
\d{9}- Matches exactly 9 digits after “S”, making a total of 10 characters

@anjali123,

For extracting Order IDs that consist of 10 digits and start with an “S” from your input text using Regex in UiPath, you can use the following pattern:

S\d{9}

This pattern ensures that the Order ID starts with the letter ‘S’ followed by exactly 9 digits, making a total of 10 characters.

To integrate this in your UiPath workflow for extracting Order IDs from a given input string, follow these steps:

Assign Activity: Place the input string (e.g., data from a file) into a variable.
Matches Activity: Use the Matches activity to apply the Regex pattern S\d{9} to the input string.
For Each Activity: Iterate through the matches to process the extracted Order IDs.
Here is a sample implementation in UiPath:

Assign Activity:

inputText = "972856857 7067059409 S123456789 Lghhjkjkb8999
             972856757 7069656941 S153375999 Lghhjkjkb8999
             972856757 7069656941 S153375000"

Matches Activity:

Input: inputText
Pattern: S\d{9}
For Each Activity:

Type argument:
System.Text.RegularExpressions.Match
Values: The output of the Matches activity
Body: Add logic to process each match.Value.
This should yield the expected output:

S123456789
S153375999
S153375000

By using S\d{9}, you have a precise and efficient way to ensure the Order IDs meet your specified format requirement.

LLM helped me to write this but it’s validated by me.

Hi @anjali123

Then use the below regular expression to get the output as you required, Store the input in a variable called Input,

- Assign -> Output = String.Join(Environment.Newline, System.Text.RegularExpressions.Regex.Matches(Input.toString, "S\d{9}").Cast(Of Match)().Select(Function(X) X.Value).tolist())

Hope it helps!!

You should try Read Text File and then Generate Data Table.

1 Like

Try to use this one.

Assign Activity to extract the Order IDs:

Use the Regex.Matches method to find all matches and convert the results into a list of strings. The correct syntax for the Assign activity is:

orderIDs = System.Text.RegularExpressions.Regex.Matches(str_string, "(?<=\t)S\d{9}").Cast(Of Match)().Select(Function(m) m.Value).ToList()

Now use the List with For Each Activity to loop through orderIDs and log them

Hope it helps!, please try this one and mark it as a solution if it helps, Thank You.