how to get item filter by id with regex?












0















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










share|improve this question























  • 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


















0















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










share|improve this question























  • 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
















0












0








0


1






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










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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





















  • 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














1 Answer
1






active

oldest

votes


















1














(?:(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






share|improve this answer


























  • 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 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
});


}
});














draft saved

draft discarded


















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









1














(?:(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






share|improve this answer


























  • 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
















1














(?:(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






share|improve this answer


























  • 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














1












1








1







(?:(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






share|improve this answer















(?:(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







share|improve this answer














share|improve this answer



share|improve this answer








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



















  • 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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Liquibase includeAll doesn't find base path

How to use setInterval in EJS file?

Petrus Granier-Deferre