Hi Team need regex value for below string

Hi team,

my string value is str=“[\r\n {\r\n "guid": "7a84a331-7a8f-452e-b42e-7819a15db756",\r\n "companyName": "S&S Activewear",\r\n "warehouseAbbr": "IL",\r\n "orderNumber": "58112299",\r\n "invoiceNumber": "",\r\n "poNumber": "9062157",\r\n "customerNumber": "402210",\r\n "orderDate": "2024-12-02T05:21:21.807",\r\n "expectedDeliveryDate": "2024-12-03T00:00:00",\r\n "orderType": "API",\r\n "terms": "Credit Card",\r\n "orderStatus": "In Progress",\r\n "dropship": false,\r\n "shippingCarrier": "UPS",\r\n "shippingMethod": "UPS Ground",\r\n "shipBlind": false,\r\n "shippingCollectNumber": "",\r\n "shippingAddress": {\r\n "customer": "UI Path",\r\n "attn": "",\r\n "address": "220 Remington Blvd",\r\n "city": "Bolingbrook",\r\n "state": "IL",\r\n "zip": "60440"\r\n },\r\n "subtotal": 47.00,\r\n "shipping": 14.86,\r\n "shippingSaved": 0.00,\r\n "cod": 0.00,\r\n "tax": 0.00,\r\n "lostCashDiscount": 0.00,\r\n "smallOrderFee": 0.00,\r\n "cuponDiscount": 0.00,\r\n "sampleDiscount": 0.00,\r\n "setUpFee": 0.00,\r\n "restockFee": 0.00,\r\n "debitCredit": 0.00,\r\n "total": 61.86,\r\n "totalPieces": 0,\r\n "totalLines": 0,\r\n "totalWeight": 5.71,\r\n "totalBoxes": 1,\r\n "deliveryStatus": "",\r\n "conveyorLane": "A",\r\n "lines": [\r\n {\r\n "lineNumber": 1,\r\n "type": "S",\r\n "skuID": 2421325,\r\n "sku": "B22060003",\r\n "gtin": "00821780033342",\r\n "yourSku": "",\r\n "qtyOrdered": 5,\r\n "price": 9.40,\r\n "brandName": "Gildan",\r\n "styleName": "18500",\r\n "title": "Heavy Blend™ Hooded Sweatshirt",\r\n "colorName": "White",\r\n "sizeName": "S",\r\n "returnable": true\r\n }\r\n ]\r\n }\r\n]”

in this I need order number that order number changed dynamically

can you anyone help me on this please
Regards
Sai

Hey @Mada_Sai_Krishna
can you try below and let us know if it works for you
(?<=orderNumber": ")\d+

@Mada_Sai_Krishna,

This is a JSON string so you can easily get the order number by desterilizing the JSON using below code.

jsonObjectVariable = Newtonsoft.Json.JsonConvert.DeserializeObject(Of JObject)(strVariable)

Get order number in string variable

orderNumberVariable = jsonObject("orderNumber").ToString()

Your String is JSON so we suggest using related apporaches for the extraction

grafik

can you please provide example here when I’m try to use this sentence getting error I’m using C#

@ppr can you please provide the snapshots of that it will really helpful

@Mada_Sai_Krishna,

Deserialize with this.

jsonObjectVariable = Newtonsoft.Json.Linq.JObject.Parse(jsonString);

Get order number in string variable

orderNumberVariable = jsonObject["orderNumber"].ToString()

sorry, it’s not working @ashokkarale

@Mada_Sai_Krishna,

Any specific error?

To get the order number from your JSON string in UiPath, first, save the JSON string in a variable (e.g., strJson). Then, use the Deserialize JSON activity to convert it into a JSON object. Finally, use an Assign activity to extract the order number with jsonObject("orderNumber").ToString. This will give you the order number, even if it changes each time.

Hey @Mada_Sai_Krishna

Here is the regex for your query:

"(?<=orderNumber"": "")\d+"

Use a Assign Activity:

str_OrderNumber = System.Text.RegularExpressions.Regex.Match(str_Input,“(?<=orderNumber”“: “”)\d+”).ToString

Screenshot for your reference:

Best regards,
Ajay Mishra