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",
2
  • Only EFM needs to be replaced? Commented Sep 1, 2015 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? Commented Sep 1, 2015 at 20:43

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Whilst this works. I unfortunately left out some important information. Give me a second
@DarylGill I updated my answer. However, I don't see any regex you need to look for a simple string.
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(?=")

6 Comments

what does \K stand for in that regex?
@gion_13 \K will match and discard it from the final match.
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 \K is not there in javascript.Only pcre
Yes, I've noticed that and there seems to be a very short list of regex implementation that do support it:stackoverflow.com/a/13543042/491075. However, that answer lists notepad++ in the not supporting \K list.
|
1

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

Replace with: \1somethingdifferent\2

Options: Regular expression, Wrap around

enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.