Home > other >  Regex for removing specific pattern from string in c#
Regex for removing specific pattern from string in c#

Time:06-21

I have a string, which is containing JSON objects, I want to remove a specific pattern of characters from string i.e. _6": (where number could be from 1 to 50).

JSON STRING :

"Toner_Request_Details": [
        {
          "Item_Code1": {
            "id": "80636.0"
          },
          "Current_Stock1": "4",
          "Quantity_Req": "5",
          "Item_Code1_1": {
            "id": "80637.0"
          },
          "Current_Stock1_2": "8",
          "Quantity_Req_3": "9",
          "Item_Code1_4": {
            "id": "80638.0"
          },
          "Current_Stock1_5": "12",
          "Quantity_Req_6": "13",
          "Item_Code1_7": {
            "id": "80639.0"
          },
          "Current_Stock1_8": "16",
          "Quantity_Req_9": "17",
          "Item_Code1_10": {
            "id": "80640.0"
          },
          "Current_Stock1_11": "20",
          "Quantity_Req_12": "21"
        }
      ]

I want to make, Item_Code1_1 to Item_Code1 Current_Stock1_2 to Current_Stock1 and so on...

Please help me write a regex to remove pattern from string.

CodePudding user response:

Regex.Replace(json, "_\d ", "");
  • Related