Open andersonpem opened 1 month ago
Adding to my queue in the project at https://taskavel.com/
Also, again, thank you for bringing this to my attention.
Z.
Gogogo 🤓
From your experience, performance-wise, which one is better?
I think using regex is usually faster. For simple regular expressions that might not cause regressions and need a different regex engine like the RE2 of Golang like when the Cloudflare regex issue took them down due to infinite backtrack, then using regex is advisable.
It all comes down to how predictable the expression is. In the case of CPF and CNPJ, we need to do extra calculations to make sure a number is valid.
In the case of a random key, all we need to do is check if the format matches, because there's no inherent validation check logic to the data.
I have also written a framework in PHP from scratch to study how routers, dependency injection and other aspects work. By far the fastest and more performant approach for route resolution (that is quite more complex than this) was to match things with regex. And then implement logic from there. I got very happy when I made dependency injection work from scratch :stuck_out_tongue: I felt very proud.
So, yes. Considering the nature of the data, regex will do.
Linear time regex engines are very interesting.
"Let this be a warning to all who are performing extremely convoluted regex matching at scale". Wise words. And you cannot go bigger than Cloudflare.
Very well. We're not cloudflaring our way through the problem, so I'd say using regex is pretty safe, quick and efficient (dirty?)
Updated task at Taskavel. Give me some time to cook this up.
I have also written a framework in PHP from scratch
Also, can you share this with me? I wanna see how you implemented Dependency Injection.
Z.
Alright. Check Discord.
PHP 8.4 was just released. We're now at 8.4.1. Tests passed :)
We missed the random type key in our implementation. I actually started the conversation in the wrong repo :stuck_out_tongue: https://github.com/Phillarmonic/cpf-cnpj/issues/5
We have a regex for that. https://developers.international.pagseguro.com/reference/pix-key-validation-and-regex
Very similar to a uuid.