Regex replace over-selecting for no apparent reason
I guess I'm just not seeing how to format the regex to select only a portion like this:
`$now->format('Y-m-d H:i:s')`
I'm trying to convert it to something like this:
`$format($now)`
In the regex, I tried making `(.*)` be `(.*)?` or `(.?)` (usually my fix for over-selecting), but nothing I'm trying is fixing it. I'm pretty sure my regex is bad, but I'm not seeing how to fix it.
Not that you need to know, but here's the `$format` function in case you're curious:
$format = function(\DateTime $date) {
return $date->format('Y-m-d');
};
Please sign in to leave a comment.
Hi there,
\$.*-> will match all from the first $ until it finds -> . This part works correctly.
Better limit it with allowed symbols only. Something like:
Replace:
Test code:
How it looks:
P.S.
https://regex101.com/ -- a good place to test/making your regex