Can someone please help with the regex patter for the below expression ? [{\"controlNumber\":\"TEST082820230838038145467288\"}

From this expression ,
[{"controlNumber":"TEST082820230838038145467288"}

I want only TEST082820230838038145467288

Kindly help me with the regex pattern.

Hi @Ragavi_Rajasekar

Try this

\w+\d+

@Ragavi_Rajasekar

system.text.regularexpression.regex.match(inputstr,“(?<=:.*)\w+”).value

or you can use below

hope this helps

1 Like

Hi @Ragavi_Rajasekar

Input= "[{"controlNumber":"TEST082820230838038145467288"}"
Output= System.Text.RegularExpressions.Regex.Match(Input,"[A-Z]+\d+").Value

Both variables are of DataType System.String.

Hope it helps!!

the string looks like a JSON string. If so, we would recommend to handle it with JSON related approaches and options instead with Regex

1 Like

I agree with Peter, It might be a more future proof solution for you to use the Deserialize JSON activity @Ragavi_Rajasekar
That way you can pull any other values in and reference them as needed.
image

I am getting the json output from http request as this .
{
“message”: "{"acdvReqResponse":{"transactionId":"7E34B91A1697168556724","message":{"id":"SUCCESS","value":"ACDV Case Results have been retrieved"},"acdvReqs":[{"controlNumber":"TEST082820230838038145467288"},{"controlNumber":"TEST082820230838038145468288"},

Multiple control numbers are coming . For each is not working after deserialisation.

Hi @Ragavi_Rajasekar ,

You can use different regex patterns like:

  1. If you want text preceded with “controlNumber” field then you can use:
    (?<=controlNumber":")[a-zA-Z0-9]+

  2. If you want text including TEST and followed digits, you can use:
    TEST\w+ or TEST\d+ if they are digits always.

@Ragavi_Rajasekar

try this :
input_string = [{“controlNumber”:“TEST082820230838038145467288”}
`

System.Text.RegularExpressions.Regex.Match(Input_string,“[A-Z]+\d+”).Value

`

cheers…!

Unfortunately, we cannot refer to the entire JSON. Maybe you can share as text file


we have to clear the detail as this part looks like a serialized string and would need a second deserialization

Maybe this also causes

Option A: (no serialized string)
grafik
grafik

Option B: (serialized string)
grafik

Hi @Ragavi_Rajasekar ,
Thanks for reaching out to UiPath community.
Here is the regex pattern you can use for extracting the desired text.
“controlNumber”:“(.*?)”

Happy Automation :grinning:

Thanks,
@pratik.maskar

Thanks Peter I’ll try

Thank you for the inputs

Hi @Ragavi_Rajasekar

How about this expression?

System.Text.RegularExpressions.Regex.Match(YourInputString,"[A-Za-z0-9]+(?=\W})").ToString

image

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