Need to extract the value between the text

Description

Hi There,
I am extracting a data table and the data is coming as below.
Input -
KHR P-25031 : RESOLVED summary items in List
KHR P-250350 : RESOLVED summary items in List
KHR P-2503800 : RESOLVED summary items in List
KHR P-25031500 : RESOLVED summary items in List
KHR P-250320000 : RESOLVED summary items in List
KHR P-25034000000 : RESOLVED summary items in List

I want to extract the value starting from P and till : , no space is required.
Mainly i want the value starting from P and the following integer value.
If you see after2503 the value is single,double,triple and keep on getting incremented.
Kindly suggest.
Thanks

Link

Date

2025-04-10

Related UiPath products

Studio

Hi @avinashy
Try pls,
Let,
inputString = “KHR P-25031 : RESOLVED summary items in List”

extractedValue = System.Text.RegularExpressions.Regex.Match(inputString, “P-\d+”).Value

happy Automation

@avinashy

If let another scenario,

inputString = “KHR P-25031 : RESOLVED summary items in List” & Environment.NewLine &
“KHR P-250350 : RESOLVED summary items in List” & Environment.NewLine &
“KHR P-2503800 : RESOLVED summary items in List” & Environment.NewLine &
“KHR P-25031500 : RESOLVED summary items in List”

matches = System.Text.RegularExpressions.Regex.Matches(inputString, “P-\d+”)

For Each match in matches
Log Message: match.Value.Trim

1 Like

Hey @avinashy
try this regex pattern
System.Text.RegularExpressions.Regex.Match(yourString, “P-\d+(?= :)”).Value

If you’re working with a whole DataTable, you can use a For Each Row loop and apply this to each row’s specific column:
extractedValue = Regex.Match(row(“YourColumnName”).ToString, “P-\d+(?= :)”).Value

cheers