get all text between bracket but skip nested bracketHow to replace plain URLs with links?How do I extract text that lies between parentheses (round brackets)?Secure hash and salt for PHP passwordsHow do you use a variable in a regular expression?Regular expression to extract text between square bracketsReference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?How can I write a regex which matches non greedy?regular expression to get text between brackets that have text between bracketsHow to exclude text between two curly brackets with regex?
Can the harmonic series explain the origin of the major scale?
Was the picture area of a CRT a parallelogram (instead of a true rectangle)?
Is there an wasy way to program in Tikz something like the one in the image?
Can I Retrieve Email Addresses from BCC?
What is the term when two people sing in harmony, but they aren't singing the same notes?
What does the "3am" section means in manpages?
How will losing mobility of one hand affect my career as a programmer?
Golf game boilerplate
Why are all the doors on Ferenginar (the Ferengi home world) far shorter than the average Ferengi?
Can I use my Chinese passport to enter China after I acquired another citizenship?
What if somebody invests in my application?
Are taller landing gear bad for aircraft, particulary large airliners?
How do I repair my stair bannister?
Partial sums of primes
How to check participants in at events?
Why isn't KTEX's runway designation 10/28 instead of 9/27?
Java - What do constructor type arguments mean when placed *before* the type?
Are Warlocks Arcane or Divine?
Hostile work environment after whistle-blowing on coworker and our boss. What do I do?
Latex for-and in equation
Indicating multiple different modes of speech (fantasy language or telepathy)
How can a jailer prevent the Forge Cleric's Artisan's Blessing from being used?
A workplace installs custom certificates on personal devices, can this be used to decrypt HTTPS traffic?
Calculating the number of days between 2 dates in Excel
get all text between bracket but skip nested bracket
How to replace plain URLs with links?How do I extract text that lies between parentheses (round brackets)?Secure hash and salt for PHP passwordsHow do you use a variable in a regular expression?Regular expression to extract text between square bracketsReference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?How can I write a regex which matches non greedy?regular expression to get text between brackets that have text between bracketsHow to exclude text between two curly brackets with regex?
Im trying to figure out how to get the text between two bracket tags but dont stop at the first closing )
__('This is a (TEST) all of this i want') i dont want any of this;
my current pattern is __((.*?))
which gives me
__('This is a (TEST)
but i want
__('This is a (TEST) all of this i want')
Thanks
php regex regex-negation
New contributor
add a comment |
Im trying to figure out how to get the text between two bracket tags but dont stop at the first closing )
__('This is a (TEST) all of this i want') i dont want any of this;
my current pattern is __((.*?))
which gives me
__('This is a (TEST)
but i want
__('This is a (TEST) all of this i want')
Thanks
php regex regex-negation
New contributor
add a comment |
Im trying to figure out how to get the text between two bracket tags but dont stop at the first closing )
__('This is a (TEST) all of this i want') i dont want any of this;
my current pattern is __((.*?))
which gives me
__('This is a (TEST)
but i want
__('This is a (TEST) all of this i want')
Thanks
php regex regex-negation
New contributor
Im trying to figure out how to get the text between two bracket tags but dont stop at the first closing )
__('This is a (TEST) all of this i want') i dont want any of this;
my current pattern is __((.*?))
which gives me
__('This is a (TEST)
but i want
__('This is a (TEST) all of this i want')
Thanks
php regex regex-negation
php regex regex-negation
New contributor
New contributor
edited Mar 21 at 14:49
Wiktor Stribiżew
325k16146226
325k16146226
New contributor
asked Mar 21 at 14:45
Winners2113Winners2113
132
132
New contributor
New contributor
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You forgot to escape two parenthesis in your regex : __((.*))
;
Check on regex101.com.
add a comment |
You may use a regex subroutine to match text inside nested parentheses after __
:
if (preg_match_all('~__((((?:[^()]++|(?1))*)))~', $s, $matches))
print_r($matches[2]);
See the regex demo.
Details
__
- a__
substring((((?:[^()]++|(?1))*)))
- Group 1 (it will be recursed using the(?1)
subroutine):(
- a(
char((?:[^()]++|(?1))*)
- Group 2 capturing 0 or more repetitions of any 1+ chars other than(
and)
or the whole Group 1 pattern is recursed)
- a)
char.
See the PHP demo:
$s = "__('This is a (TEST) all of this i want') i dont want any of this; __(extract this)";
if (preg_match_all('~__((((?:[^()]++|(?1))*)))~', $s, $matches))
print_r($matches[2]);
// => Array ( [0] => 'This is a (TEST) all of this i want' [1] => extract this )
add a comment |
Use the pattern __((.*)?)
.
The escapes the parentheses to catch literal parentheses. This then captures all the text inside that set of parentheses.
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
);
);
Winners2113 is a new contributor. Be nice, and check out our Code of Conduct.
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%2f55283093%2fget-all-text-between-bracket-but-skip-nested-bracket%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You forgot to escape two parenthesis in your regex : __((.*))
;
Check on regex101.com.
add a comment |
You forgot to escape two parenthesis in your regex : __((.*))
;
Check on regex101.com.
add a comment |
You forgot to escape two parenthesis in your regex : __((.*))
;
Check on regex101.com.
You forgot to escape two parenthesis in your regex : __((.*))
;
Check on regex101.com.
answered Mar 21 at 14:48
iArcadiaiArcadia
1,082619
1,082619
add a comment |
add a comment |
You may use a regex subroutine to match text inside nested parentheses after __
:
if (preg_match_all('~__((((?:[^()]++|(?1))*)))~', $s, $matches))
print_r($matches[2]);
See the regex demo.
Details
__
- a__
substring((((?:[^()]++|(?1))*)))
- Group 1 (it will be recursed using the(?1)
subroutine):(
- a(
char((?:[^()]++|(?1))*)
- Group 2 capturing 0 or more repetitions of any 1+ chars other than(
and)
or the whole Group 1 pattern is recursed)
- a)
char.
See the PHP demo:
$s = "__('This is a (TEST) all of this i want') i dont want any of this; __(extract this)";
if (preg_match_all('~__((((?:[^()]++|(?1))*)))~', $s, $matches))
print_r($matches[2]);
// => Array ( [0] => 'This is a (TEST) all of this i want' [1] => extract this )
add a comment |
You may use a regex subroutine to match text inside nested parentheses after __
:
if (preg_match_all('~__((((?:[^()]++|(?1))*)))~', $s, $matches))
print_r($matches[2]);
See the regex demo.
Details
__
- a__
substring((((?:[^()]++|(?1))*)))
- Group 1 (it will be recursed using the(?1)
subroutine):(
- a(
char((?:[^()]++|(?1))*)
- Group 2 capturing 0 or more repetitions of any 1+ chars other than(
and)
or the whole Group 1 pattern is recursed)
- a)
char.
See the PHP demo:
$s = "__('This is a (TEST) all of this i want') i dont want any of this; __(extract this)";
if (preg_match_all('~__((((?:[^()]++|(?1))*)))~', $s, $matches))
print_r($matches[2]);
// => Array ( [0] => 'This is a (TEST) all of this i want' [1] => extract this )
add a comment |
You may use a regex subroutine to match text inside nested parentheses after __
:
if (preg_match_all('~__((((?:[^()]++|(?1))*)))~', $s, $matches))
print_r($matches[2]);
See the regex demo.
Details
__
- a__
substring((((?:[^()]++|(?1))*)))
- Group 1 (it will be recursed using the(?1)
subroutine):(
- a(
char((?:[^()]++|(?1))*)
- Group 2 capturing 0 or more repetitions of any 1+ chars other than(
and)
or the whole Group 1 pattern is recursed)
- a)
char.
See the PHP demo:
$s = "__('This is a (TEST) all of this i want') i dont want any of this; __(extract this)";
if (preg_match_all('~__((((?:[^()]++|(?1))*)))~', $s, $matches))
print_r($matches[2]);
// => Array ( [0] => 'This is a (TEST) all of this i want' [1] => extract this )
You may use a regex subroutine to match text inside nested parentheses after __
:
if (preg_match_all('~__((((?:[^()]++|(?1))*)))~', $s, $matches))
print_r($matches[2]);
See the regex demo.
Details
__
- a__
substring((((?:[^()]++|(?1))*)))
- Group 1 (it will be recursed using the(?1)
subroutine):(
- a(
char((?:[^()]++|(?1))*)
- Group 2 capturing 0 or more repetitions of any 1+ chars other than(
and)
or the whole Group 1 pattern is recursed)
- a)
char.
See the PHP demo:
$s = "__('This is a (TEST) all of this i want') i dont want any of this; __(extract this)";
if (preg_match_all('~__((((?:[^()]++|(?1))*)))~', $s, $matches))
print_r($matches[2]);
// => Array ( [0] => 'This is a (TEST) all of this i want' [1] => extract this )
answered Mar 21 at 14:53
Wiktor StribiżewWiktor Stribiżew
325k16146226
325k16146226
add a comment |
add a comment |
Use the pattern __((.*)?)
.
The escapes the parentheses to catch literal parentheses. This then captures all the text inside that set of parentheses.
add a comment |
Use the pattern __((.*)?)
.
The escapes the parentheses to catch literal parentheses. This then captures all the text inside that set of parentheses.
add a comment |
Use the pattern __((.*)?)
.
The escapes the parentheses to catch literal parentheses. This then captures all the text inside that set of parentheses.
Use the pattern __((.*)?)
.
The escapes the parentheses to catch literal parentheses. This then captures all the text inside that set of parentheses.
answered Mar 21 at 14:49
k97513k97513
1,450616
1,450616
add a comment |
add a comment |
Winners2113 is a new contributor. Be nice, and check out our Code of Conduct.
Winners2113 is a new contributor. Be nice, and check out our Code of Conduct.
Winners2113 is a new contributor. Be nice, and check out our Code of Conduct.
Winners2113 is a new contributor. Be nice, and check out our Code of Conduct.
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%2f55283093%2fget-all-text-between-bracket-but-skip-nested-bracket%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