I wonder how i can exclude a substring from the result after it matches the pattern.
example:
<a href="?page1"><?php __('string1');?></a>
<a href="?page2"><?php __("string2");?></a>
I want to get only the strings passed as parameters to the __() function. i tried this regex:
'/__\(((\'([^\']+)\')|(\"([^\"]+)\"))/'
but that returns ‘string1’ and “string2” wrapped in single quotes and double quotations.
how can i exclude single quotes and double quotations?
Try this
You can see it online here on Regexr
Every time when you open a round bracket you create a capturing group. So, if you don’t want it use
(?:)this would define a non capturing group. I don’t use this here. I rewrote your regex a bit. In my first group I check if there are'or"and store them into group 1. later on I use the backreference\1to this group one, to use the correct character.Your result is then stored always into group 2. How you access this result depends on your used language.