I have the following text
$text = 'This is a test to see if something(try_(this(once))) works';
I need to get something(try_(this(once))) with regex from the text. I have the following issue
My nesting will not remain constant, my text can be
something(try_(this(once)))orsomething(try_this(once))orsomething(try_thisonce)
I have tried a number of regex found across the site, but cannot get it working. Here is the closest I have come
EXAMPLE 1:
$text = 'This is a test to see if something(try_(this(once))) works';
$output = preg_match_all('/(\(([^()]|(?R))*\))/', $text, $out);
?><pre><?php var_dump($out[0]); ?></pre><?php
This outputs
array(1) {
[0]=>
string(18) "(try_(this(once)))"
}
No matter where I add the word something(for example '/something(\(([^()]|(?R))*\))/' and '/(\something(([^()]|(?R))*\))/'), I get an empty array or NULL
EXAMPLE 2
$text2 = 'This is a test to see if something(try_(this(once))) works';
$output2 = preg_match_all('/something\((.*?)\)/', $text2, $out2);
?><pre><?php var_dump($out2[0]); ?></pre><?php
With this code I do get the word something back,
array(1) {
[0]=>
string(25) "something(try_(this(once)"
}
but then the expression stops and return after the first closing ) which is expected as this is not a recursive expression
How do I recursively match and return a nested parenthesis with the word something before the first opening (, and if possible, what happens then there might or might not be a whitespace before the word something, for example
something(try_(this(once)))orsomething (try_(this(once)))
something(try_(this(once))), butsomething (try_(this(once)))returns nothing. Any idea how to match the whitespace in the event one might or might not occur, post it as an answer please so I can give you some credit