I'm (finally) starting to learn regex, and I'm wondering if there's any notable difference between these two pattern strings. I'm trying to match lines such as "Title=Blah
", and match "Title" and "Blah" in two groups.
The problem comes with titles like "Title=The = operator
". Here are the two choices to solve the problem:
^([^=]+)=(.+)$
^(.+?)=(.+)$
Is there any difference between the two, either performance-wise or functionality-wise?
The first one requires that there be at least one non-=
character before an =
in order to match, where the second doesn't; it'll match on a leading ==
.
As to performance, I don't anticipate a meaningful difference, but if you truly care, the only thing to do is profile it. Which I would do by writing a pair of scripts, each running one of the methods a few hundred thousand times, and timing them using the Unix time
command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With