in reply to Re^6: regex in REPLACEMENT in s///
in thread regex in REPLACEMENT in s///
And as the Monks prefer, no grouping () to be seen.
Just to nail this point, I doubt anyone has good grounds to object to relevant use of grouping. The problem is that by default using brackets creates a capture group and this results in 2 levels of potential inefficiency (the group and the capture). And that's not to say that capture groups are bad - far from it. There is just no point in paying the performance penalty if you don't need the capturing.
The inefficiencies being discussed here are obviously small but if you are using such a regex in the middle of tight loop which runs millions/billions of times then these things mount up so it is as well to be aware of them. I wouldn't go tying myself in knots to avoid them in cases where they don't matter.
In general:
We've all seen code where people have sprinkled unnecessary characters. In most cases it has no effect (good or bad) and just makes the code harder to read and maintain. With brackets in regex there is an effect and the price is worth paying if your code makes use of the functionality. But if you don't need it then it is best avoided.
🦛
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: regex in REPLACEMENT in s///
by perlboy_emeritus (Scribe) on Sep 15, 2023 at 16:35 UTC |