0

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",
Daryl Gill
  • 5,238
  • 7
  • 31
  • 68
  • Only `EFM` needs to be replaced? – vks Sep 01 '15 at 20:23
  • Are you meaning from `second set of quotes` as only for the `equipedWeapon.id` and to leave `equipedOutfit.id` unchanged or just the value of any `id`? – Will B. Sep 01 '15 at 20:43

3 Answers3

2

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.

Federico Piazza
  • 27,409
  • 11
  • 74
  • 107
1
"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(?=")
vks
  • 63,206
  • 9
  • 78
  • 110
  • what does `\K` stand for in that regex? – gion_13 Sep 01 '15 at 20:58
  • @gion_13 `\K` will match and discard it from the final match. – vks Sep 01 '15 at 21:00
  • 1
    Very informative... I come from a javascript background and it's the first time I've ever heard of this regex special character. Thanks! – gion_13 Sep 01 '15 at 21:06
  • @gion_13 `\K` is not there in `javascript`.Only `pcre` – vks Sep 01 '15 at 21:08
  • Yes, I've noticed that and there seems to be a very short list of regex implementation that do support it:http://stackoverflow.com/a/13543042/491075. However, that answer lists *notepad++* in the not supporting `\K` list. – gion_13 Sep 01 '15 at 21:12
  • @gion_13 `notepad++` version 6 and above supports `\K` – vks Sep 01 '15 at 21:13
1

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

Replace with: \1somethingdifferent\2

Options: Regular expression, Wrap around

enter image description here

Will B.
  • 14,243
  • 4
  • 56
  • 62