I have an example:
some text lorem ipsum ... {gallery}../2021/some_string_2021/some_other_string{/gallery} ... other lorem ipsum
And I need to get out only the ../2021/some_string_2021/some_other_string.
How can I ignore all before {gallery} and all after {/gallery} while being able to capture ../2021/some_string_2021/some_other_string?
Tried to figure it out but cannot make it work neither with some sort of combination with:
preg_match_all("/\[(.*?)\]/", $text, $matches);
print_r($matches[1]);
if( preg_match( '!\(([^\)]+)\)!', $text2, $match ) )
echo $match[1];
Maybe I should first change [] to {}, and then try it with (.*?){(.*?)} ?
preg_match('#(?<=\{gallery}).*?(?=\{/gallery})#', $str, $matches); echo $matches[0];#\{gallery}\K.*?(?=\{/gallery})#on the sample string will reduce the step count from 191 to 110. Furthermore, capturing and referencing the opening tagname with#\{(gallery)}\K.*?(?=\{/\1})#will reduce the step count down to 107 while reducing the pattern length and eliminating the possible occurrence of typo-mismatching between the opening and closing tagname.