Daryl Gill
Daryl Gill

Reputation: 5524

Replace specific part of a string

I'm currently encountering a pickle in modifications of a document. Lets say for example, I have this chunk of text:

                "id": "EFM",
                "type": "Casual",
                "hasBeenAssigned": false,
                "hasRandomAssigned": false
            },

I currently have roughly 73 - 80 occourances of:

 "id" : "somethingdifferent",

Using a regular expression in notepad++, How can I select the entire string:

 "id" : "",

but only change the contents between the second set of quotes?


Edit

An oversight made me leave this information out:

"equipedOutfit": {
                    "id": "MkIV",
                    "type": "Outfit",
                    "hasBeenAssigned": false,
                    "hasRandonAssigned": false
                },
                "equipedWeapon": {
                    "id": "EFM",
                    "type": "Casual",
                    "hasBeenAssigned": false,
                    "hasRandonAssigned": false
                },

The selected text, looking for is:

 "id" : "EFM",

Upvotes: 0

Views: 66

Answers (3)

Will B.
Will B.

Reputation: 18426

Find what: ("id"\s?:\s?").*(")

Replace with: \1somethingdifferent\2

Options: Regular expression, Wrap around

enter image description here

Upvotes: 1

Federico Piazza
Federico Piazza

Reputation: 31035

You can use a regex like this:

("id": ").*?"

With a replacement string:

$1whatever"
  ^^^^^^^^--- replace 'whatever' with whatever you want

Working demo

enter image description here

Update: as you updated your question, I'm updating the answer. If you want only to replace "id": "EFM" then you have just to look for that text only and put the replacement string you want.

Upvotes: 2

vks
vks

Reputation: 67988

"id":\s*"\K[^"]*

You can use \K here and replace by whatever you want.See demo.

https://regex101.com/r/sS2dM8/29

EDIT:

If you want only EFM then use

"id"\s*:\s*"\KEFM(?=")

Upvotes: 1

Related Questions