how to get item filter by id with regex?
I have a text
{
"item":
{
id = 1,
something
value="value1"
something
}
"item":
{
value="value2"
something
id = 2,
something
}
"item":
{
id = 3,
something
value="value3"
something
}
}
I want to get value by id
I had try
(value=.*)[wW]*?id = 2
but it get value="value1"
https://regex101.com/r/xraGIQ/1
regex
add a comment |
I have a text
{
"item":
{
id = 1,
something
value="value1"
something
}
"item":
{
value="value2"
something
id = 2,
something
}
"item":
{
id = 3,
something
value="value3"
something
}
}
I want to get value by id
I had try
(value=.*)[wW]*?id = 2
but it get value="value1"
https://regex101.com/r/xraGIQ/1
regex
What language/tool are you using?
– Toto
Jan 20 at 12:56
How about regex101.com/r/xraGIQ/2
– Toto
Jan 20 at 13:01
I use python3 re
– ywaby
Jan 20 at 13:37
This problem has troubled me all day, thank you very much for your answer.exactly the answer I want.
– ywaby
Jan 20 at 13:53
So you only wanted the value when id=2 not id=1 or 3? Because if you wanted it for any id the accepted answer doesn't work.
– Mark
Jan 20 at 14:12
add a comment |
I have a text
{
"item":
{
id = 1,
something
value="value1"
something
}
"item":
{
value="value2"
something
id = 2,
something
}
"item":
{
id = 3,
something
value="value3"
something
}
}
I want to get value by id
I had try
(value=.*)[wW]*?id = 2
but it get value="value1"
https://regex101.com/r/xraGIQ/1
regex
I have a text
{
"item":
{
id = 1,
something
value="value1"
something
}
"item":
{
value="value2"
something
id = 2,
something
}
"item":
{
id = 3,
something
value="value3"
something
}
}
I want to get value by id
I had try
(value=.*)[wW]*?id = 2
but it get value="value1"
https://regex101.com/r/xraGIQ/1
regex
regex
asked Jan 20 at 12:08
ywabyywaby
81
81
What language/tool are you using?
– Toto
Jan 20 at 12:56
How about regex101.com/r/xraGIQ/2
– Toto
Jan 20 at 13:01
I use python3 re
– ywaby
Jan 20 at 13:37
This problem has troubled me all day, thank you very much for your answer.exactly the answer I want.
– ywaby
Jan 20 at 13:53
So you only wanted the value when id=2 not id=1 or 3? Because if you wanted it for any id the accepted answer doesn't work.
– Mark
Jan 20 at 14:12
add a comment |
What language/tool are you using?
– Toto
Jan 20 at 12:56
How about regex101.com/r/xraGIQ/2
– Toto
Jan 20 at 13:01
I use python3 re
– ywaby
Jan 20 at 13:37
This problem has troubled me all day, thank you very much for your answer.exactly the answer I want.
– ywaby
Jan 20 at 13:53
So you only wanted the value when id=2 not id=1 or 3? Because if you wanted it for any id the accepted answer doesn't work.
– Mark
Jan 20 at 14:12
What language/tool are you using?
– Toto
Jan 20 at 12:56
What language/tool are you using?
– Toto
Jan 20 at 12:56
How about regex101.com/r/xraGIQ/2
– Toto
Jan 20 at 13:01
How about regex101.com/r/xraGIQ/2
– Toto
Jan 20 at 13:01
I use python3 re
– ywaby
Jan 20 at 13:37
I use python3 re
– ywaby
Jan 20 at 13:37
This problem has troubled me all day, thank you very much for your answer.exactly the answer I want.
– ywaby
Jan 20 at 13:53
This problem has troubled me all day, thank you very much for your answer.exactly the answer I want.
– ywaby
Jan 20 at 13:53
So you only wanted the value when id=2 not id=1 or 3? Because if you wanted it for any id the accepted answer doesn't work.
– Mark
Jan 20 at 14:12
So you only wanted the value when id=2 not id=1 or 3? Because if you wanted it for any id the accepted answer doesn't work.
– Mark
Jan 20 at 14:12
add a comment |
1 Answer
1
active
oldest
votes
(?:(id = d+)[^{}]*?(value="[^"rn]*")|(value="[^"rn]*")[^{}]*?(id = d+))
will match all pairs id/value
Explanation:
(?:
(id = d+) # group 1, id
[^{}]*? # 0 or more any character but curly braces
(value="[^"rn]*") # group 2, value
| # OR
(value="[^"rn]*") # group 3, value
[^{}]*? # 0 or more any character but curly braces
(id = d+) # group 4, id
)
Demo
your demo link does not work
– dopstar
Jan 20 at 14:01
@dopstar: Thanks you, fixed. I don't know what happened, it was working few minutes ago.
– Toto
Jan 20 at 14:05
i think you should include the braces in your negative lookahead to at least avoid this: regex101.com/r/YWooji/2
– dopstar
Jan 20 at 14:09
@dopstar: You're right, updated.
– Toto
Jan 20 at 14:15
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54276265%2fhow-to-get-item-filter-by-id-with-regex%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
(?:(id = d+)[^{}]*?(value="[^"rn]*")|(value="[^"rn]*")[^{}]*?(id = d+))
will match all pairs id/value
Explanation:
(?:
(id = d+) # group 1, id
[^{}]*? # 0 or more any character but curly braces
(value="[^"rn]*") # group 2, value
| # OR
(value="[^"rn]*") # group 3, value
[^{}]*? # 0 or more any character but curly braces
(id = d+) # group 4, id
)
Demo
your demo link does not work
– dopstar
Jan 20 at 14:01
@dopstar: Thanks you, fixed. I don't know what happened, it was working few minutes ago.
– Toto
Jan 20 at 14:05
i think you should include the braces in your negative lookahead to at least avoid this: regex101.com/r/YWooji/2
– dopstar
Jan 20 at 14:09
@dopstar: You're right, updated.
– Toto
Jan 20 at 14:15
add a comment |
(?:(id = d+)[^{}]*?(value="[^"rn]*")|(value="[^"rn]*")[^{}]*?(id = d+))
will match all pairs id/value
Explanation:
(?:
(id = d+) # group 1, id
[^{}]*? # 0 or more any character but curly braces
(value="[^"rn]*") # group 2, value
| # OR
(value="[^"rn]*") # group 3, value
[^{}]*? # 0 or more any character but curly braces
(id = d+) # group 4, id
)
Demo
your demo link does not work
– dopstar
Jan 20 at 14:01
@dopstar: Thanks you, fixed. I don't know what happened, it was working few minutes ago.
– Toto
Jan 20 at 14:05
i think you should include the braces in your negative lookahead to at least avoid this: regex101.com/r/YWooji/2
– dopstar
Jan 20 at 14:09
@dopstar: You're right, updated.
– Toto
Jan 20 at 14:15
add a comment |
(?:(id = d+)[^{}]*?(value="[^"rn]*")|(value="[^"rn]*")[^{}]*?(id = d+))
will match all pairs id/value
Explanation:
(?:
(id = d+) # group 1, id
[^{}]*? # 0 or more any character but curly braces
(value="[^"rn]*") # group 2, value
| # OR
(value="[^"rn]*") # group 3, value
[^{}]*? # 0 or more any character but curly braces
(id = d+) # group 4, id
)
Demo
(?:(id = d+)[^{}]*?(value="[^"rn]*")|(value="[^"rn]*")[^{}]*?(id = d+))
will match all pairs id/value
Explanation:
(?:
(id = d+) # group 1, id
[^{}]*? # 0 or more any character but curly braces
(value="[^"rn]*") # group 2, value
| # OR
(value="[^"rn]*") # group 3, value
[^{}]*? # 0 or more any character but curly braces
(id = d+) # group 4, id
)
Demo
edited Jan 20 at 14:45
answered Jan 20 at 13:58
TotoToto
65.7k175698
65.7k175698
your demo link does not work
– dopstar
Jan 20 at 14:01
@dopstar: Thanks you, fixed. I don't know what happened, it was working few minutes ago.
– Toto
Jan 20 at 14:05
i think you should include the braces in your negative lookahead to at least avoid this: regex101.com/r/YWooji/2
– dopstar
Jan 20 at 14:09
@dopstar: You're right, updated.
– Toto
Jan 20 at 14:15
add a comment |
your demo link does not work
– dopstar
Jan 20 at 14:01
@dopstar: Thanks you, fixed. I don't know what happened, it was working few minutes ago.
– Toto
Jan 20 at 14:05
i think you should include the braces in your negative lookahead to at least avoid this: regex101.com/r/YWooji/2
– dopstar
Jan 20 at 14:09
@dopstar: You're right, updated.
– Toto
Jan 20 at 14:15
your demo link does not work
– dopstar
Jan 20 at 14:01
your demo link does not work
– dopstar
Jan 20 at 14:01
@dopstar: Thanks you, fixed. I don't know what happened, it was working few minutes ago.
– Toto
Jan 20 at 14:05
@dopstar: Thanks you, fixed. I don't know what happened, it was working few minutes ago.
– Toto
Jan 20 at 14:05
i think you should include the braces in your negative lookahead to at least avoid this: regex101.com/r/YWooji/2
– dopstar
Jan 20 at 14:09
i think you should include the braces in your negative lookahead to at least avoid this: regex101.com/r/YWooji/2
– dopstar
Jan 20 at 14:09
@dopstar: You're right, updated.
– Toto
Jan 20 at 14:15
@dopstar: You're right, updated.
– Toto
Jan 20 at 14:15
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54276265%2fhow-to-get-item-filter-by-id-with-regex%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What language/tool are you using?
– Toto
Jan 20 at 12:56
How about regex101.com/r/xraGIQ/2
– Toto
Jan 20 at 13:01
I use python3 re
– ywaby
Jan 20 at 13:37
This problem has troubled me all day, thank you very much for your answer.exactly the answer I want.
– ywaby
Jan 20 at 13:53
So you only wanted the value when id=2 not id=1 or 3? Because if you wanted it for any id the accepted answer doesn't work.
– Mark
Jan 20 at 14:12