how do i extract info contained on
{...}
[...]
(...)
/*...*/
and <...>
using regex?
i mean: everything that's not between and of course including brackets must go.
regex to preserve comments removing everything else
Re: regex to preserve comments removing everything else
Probably not the most elegant way...
Code: Select all
$a = <<<>>>
This [text1] is...
This (text2) is...
This {text3} is...
This <text4> is...
This /*text5*/ is...
>>>;
$b = regexreplace($a, ".*([[<({]|/\*)(.*?)([]>)}]|\*/).*", "$2");
text $b;
One of my scripts helped you out? Please donate via Paypal
Re: regex to preserve comments removing everything else
thanks much highend.
i've tried hard but can't let it work: is there a way to preserve all respective brackets?
i've tried hard but can't let it work: is there a way to preserve all respective brackets?
Re: regex to preserve comments removing everything else
And what did you try exactly?i've tried hard
Elaborate more...is there a way to preserve all respective brackets?
One of my scripts helped you out? Please donate via Paypal
Re: regex to preserve comments removing everything else
the attempts we made messing up the regex.highend wrote:And what did you try exactly?i've tried hard
Elaborate more...is there a way to preserve all respective brackets?
i need to have
[text1]
(text2)
{text3}
<text4>
instead of
text1
text2
text3
text4
Re: regex to preserve comments removing everything else
The regex itself doesn't need to be modified to accomplish that...
You just have to change the replacement from $2 to $1$2$3...
You just have to change the replacement from $2 to $1$2$3...
One of my scripts helped you out? Please donate via Paypal
Re: regex to preserve comments removing everything else
solved, thanks much.highend wrote:The regex itself doesn't need to be modified to accomplish that...
You just have to change the replacement from $2 to $1$2$3...
XYplorer Beta Club