how to capture group within capture group?
for example, string:
bla bla bla (bla oops bla
bla bla bla
bla bla bla) bla oops
bla bla bla
oops bla (bla bla oops
bla)
how i can get 'oops' between brackets?
first, i get text between brackets:
(?<=()([wW]*?)(?=))
can i in the same regex capture group within capture group (find 'oops' within capture group)?
regex pcre
|
show 2 more comments
for example, string:
bla bla bla (bla oops bla
bla bla bla
bla bla bla) bla oops
bla bla bla
oops bla (bla bla oops
bla)
how i can get 'oops' between brackets?
first, i get text between brackets:
(?<=()([wW]*?)(?=))
can i in the same regex capture group within capture group (find 'oops' within capture group)?
regex pcre
If you have PHP,([^()]*Koops(?=[^()]*))
. In .NET,(?<=([^()]*)oops(?=[^()]*))
.
– Wiktor Stribiżew
Nov 27 '18 at 17:31
See stackoverflow.com/questions/23342679/…, too
– Wiktor Stribiżew
Nov 27 '18 at 17:34
Eventually, a lot depends on what you need to get in the end (usually, extract or replace).
– Wiktor Stribiżew
Nov 27 '18 at 17:46
What is the language?
– JohnyL
Nov 27 '18 at 19:58
@WiktorStribiżew thank you so much for php-regex!!!!!!!!! Now I understand howK
works.
– Alexander
Nov 28 '18 at 4:28
|
show 2 more comments
for example, string:
bla bla bla (bla oops bla
bla bla bla
bla bla bla) bla oops
bla bla bla
oops bla (bla bla oops
bla)
how i can get 'oops' between brackets?
first, i get text between brackets:
(?<=()([wW]*?)(?=))
can i in the same regex capture group within capture group (find 'oops' within capture group)?
regex pcre
for example, string:
bla bla bla (bla oops bla
bla bla bla
bla bla bla) bla oops
bla bla bla
oops bla (bla bla oops
bla)
how i can get 'oops' between brackets?
first, i get text between brackets:
(?<=()([wW]*?)(?=))
can i in the same regex capture group within capture group (find 'oops' within capture group)?
regex pcre
regex pcre
edited Nov 28 '18 at 8:17
Wiktor Stribiżew
321k16141223
321k16141223
asked Nov 27 '18 at 17:30
AlexanderAlexander
255
255
If you have PHP,([^()]*Koops(?=[^()]*))
. In .NET,(?<=([^()]*)oops(?=[^()]*))
.
– Wiktor Stribiżew
Nov 27 '18 at 17:31
See stackoverflow.com/questions/23342679/…, too
– Wiktor Stribiżew
Nov 27 '18 at 17:34
Eventually, a lot depends on what you need to get in the end (usually, extract or replace).
– Wiktor Stribiżew
Nov 27 '18 at 17:46
What is the language?
– JohnyL
Nov 27 '18 at 19:58
@WiktorStribiżew thank you so much for php-regex!!!!!!!!! Now I understand howK
works.
– Alexander
Nov 28 '18 at 4:28
|
show 2 more comments
If you have PHP,([^()]*Koops(?=[^()]*))
. In .NET,(?<=([^()]*)oops(?=[^()]*))
.
– Wiktor Stribiżew
Nov 27 '18 at 17:31
See stackoverflow.com/questions/23342679/…, too
– Wiktor Stribiżew
Nov 27 '18 at 17:34
Eventually, a lot depends on what you need to get in the end (usually, extract or replace).
– Wiktor Stribiżew
Nov 27 '18 at 17:46
What is the language?
– JohnyL
Nov 27 '18 at 19:58
@WiktorStribiżew thank you so much for php-regex!!!!!!!!! Now I understand howK
works.
– Alexander
Nov 28 '18 at 4:28
If you have PHP,
([^()]*Koops(?=[^()]*))
. In .NET, (?<=([^()]*)oops(?=[^()]*))
.– Wiktor Stribiżew
Nov 27 '18 at 17:31
If you have PHP,
([^()]*Koops(?=[^()]*))
. In .NET, (?<=([^()]*)oops(?=[^()]*))
.– Wiktor Stribiżew
Nov 27 '18 at 17:31
See stackoverflow.com/questions/23342679/…, too
– Wiktor Stribiżew
Nov 27 '18 at 17:34
See stackoverflow.com/questions/23342679/…, too
– Wiktor Stribiżew
Nov 27 '18 at 17:34
Eventually, a lot depends on what you need to get in the end (usually, extract or replace).
– Wiktor Stribiżew
Nov 27 '18 at 17:46
Eventually, a lot depends on what you need to get in the end (usually, extract or replace).
– Wiktor Stribiżew
Nov 27 '18 at 17:46
What is the language?
– JohnyL
Nov 27 '18 at 19:58
What is the language?
– JohnyL
Nov 27 '18 at 19:58
@WiktorStribiżew thank you so much for php-regex!!!!!!!!! Now I understand how
K
works.– Alexander
Nov 28 '18 at 4:28
@WiktorStribiżew thank you so much for php-regex!!!!!!!!! Now I understand how
K
works.– Alexander
Nov 28 '18 at 4:28
|
show 2 more comments
2 Answers
2
active
oldest
votes
You may use
(?:G(?!A)|()[^()]*?Koops
Or, if you must check for the closing parentheses, add a lookahead at the end:
(?:G(?!A)|()[^()]*?Koops(?=[^()]*))
See the regex demo.
Details
(?:G(?!A)|()
-(
or end of the previous match (G(?!A)
)
[^()]*?
- any 0+ chars other than(
and)
K
- match reset operator
oops
- the word you need (wrap withb
if you need a whole word match)
(?=[^()]*))
- a positive lookahead that requires 0+ chars other than(
and)
up to the first)
to appear immediately to the right of the current location.
thank you very much. You made me study regular espressions in more detail. thanks again.
– Alexander
Nov 28 '18 at 8:39
add a comment |
You can use the following regex:
(?<=()([wW]*?(oops)[wW]*?)(?=))
Basically it injects a Group
looking for 'oops'
then it doubles the '[wW]*?
' matching both before and after the captured Group.
Now 'oops'
will be in Group 2
.
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%2f53505091%2fhow-to-capture-group-within-capture-group%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You may use
(?:G(?!A)|()[^()]*?Koops
Or, if you must check for the closing parentheses, add a lookahead at the end:
(?:G(?!A)|()[^()]*?Koops(?=[^()]*))
See the regex demo.
Details
(?:G(?!A)|()
-(
or end of the previous match (G(?!A)
)
[^()]*?
- any 0+ chars other than(
and)
K
- match reset operator
oops
- the word you need (wrap withb
if you need a whole word match)
(?=[^()]*))
- a positive lookahead that requires 0+ chars other than(
and)
up to the first)
to appear immediately to the right of the current location.
thank you very much. You made me study regular espressions in more detail. thanks again.
– Alexander
Nov 28 '18 at 8:39
add a comment |
You may use
(?:G(?!A)|()[^()]*?Koops
Or, if you must check for the closing parentheses, add a lookahead at the end:
(?:G(?!A)|()[^()]*?Koops(?=[^()]*))
See the regex demo.
Details
(?:G(?!A)|()
-(
or end of the previous match (G(?!A)
)
[^()]*?
- any 0+ chars other than(
and)
K
- match reset operator
oops
- the word you need (wrap withb
if you need a whole word match)
(?=[^()]*))
- a positive lookahead that requires 0+ chars other than(
and)
up to the first)
to appear immediately to the right of the current location.
thank you very much. You made me study regular espressions in more detail. thanks again.
– Alexander
Nov 28 '18 at 8:39
add a comment |
You may use
(?:G(?!A)|()[^()]*?Koops
Or, if you must check for the closing parentheses, add a lookahead at the end:
(?:G(?!A)|()[^()]*?Koops(?=[^()]*))
See the regex demo.
Details
(?:G(?!A)|()
-(
or end of the previous match (G(?!A)
)
[^()]*?
- any 0+ chars other than(
and)
K
- match reset operator
oops
- the word you need (wrap withb
if you need a whole word match)
(?=[^()]*))
- a positive lookahead that requires 0+ chars other than(
and)
up to the first)
to appear immediately to the right of the current location.
You may use
(?:G(?!A)|()[^()]*?Koops
Or, if you must check for the closing parentheses, add a lookahead at the end:
(?:G(?!A)|()[^()]*?Koops(?=[^()]*))
See the regex demo.
Details
(?:G(?!A)|()
-(
or end of the previous match (G(?!A)
)
[^()]*?
- any 0+ chars other than(
and)
K
- match reset operator
oops
- the word you need (wrap withb
if you need a whole word match)
(?=[^()]*))
- a positive lookahead that requires 0+ chars other than(
and)
up to the first)
to appear immediately to the right of the current location.
answered Nov 28 '18 at 8:15
Wiktor StribiżewWiktor Stribiżew
321k16141223
321k16141223
thank you very much. You made me study regular espressions in more detail. thanks again.
– Alexander
Nov 28 '18 at 8:39
add a comment |
thank you very much. You made me study regular espressions in more detail. thanks again.
– Alexander
Nov 28 '18 at 8:39
thank you very much. You made me study regular espressions in more detail. thanks again.
– Alexander
Nov 28 '18 at 8:39
thank you very much. You made me study regular espressions in more detail. thanks again.
– Alexander
Nov 28 '18 at 8:39
add a comment |
You can use the following regex:
(?<=()([wW]*?(oops)[wW]*?)(?=))
Basically it injects a Group
looking for 'oops'
then it doubles the '[wW]*?
' matching both before and after the captured Group.
Now 'oops'
will be in Group 2
.
add a comment |
You can use the following regex:
(?<=()([wW]*?(oops)[wW]*?)(?=))
Basically it injects a Group
looking for 'oops'
then it doubles the '[wW]*?
' matching both before and after the captured Group.
Now 'oops'
will be in Group 2
.
add a comment |
You can use the following regex:
(?<=()([wW]*?(oops)[wW]*?)(?=))
Basically it injects a Group
looking for 'oops'
then it doubles the '[wW]*?
' matching both before and after the captured Group.
Now 'oops'
will be in Group 2
.
You can use the following regex:
(?<=()([wW]*?(oops)[wW]*?)(?=))
Basically it injects a Group
looking for 'oops'
then it doubles the '[wW]*?
' matching both before and after the captured Group.
Now 'oops'
will be in Group 2
.
answered Nov 27 '18 at 17:39
Poul BakPoul Bak
5,48831233
5,48831233
add a comment |
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%2f53505091%2fhow-to-capture-group-within-capture-group%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
If you have PHP,
([^()]*Koops(?=[^()]*))
. In .NET,(?<=([^()]*)oops(?=[^()]*))
.– Wiktor Stribiżew
Nov 27 '18 at 17:31
See stackoverflow.com/questions/23342679/…, too
– Wiktor Stribiżew
Nov 27 '18 at 17:34
Eventually, a lot depends on what you need to get in the end (usually, extract or replace).
– Wiktor Stribiżew
Nov 27 '18 at 17:46
What is the language?
– JohnyL
Nov 27 '18 at 19:58
@WiktorStribiżew thank you so much for php-regex!!!!!!!!! Now I understand how
K
works.– Alexander
Nov 28 '18 at 4:28