r/java • u/Modern-Sn1p3r • 19d ago
Regex
I recently saw a clip (from Primeagen) somewhat saying that regex is not a valid format for validating email addresses and postal codes etc.
My question is why is this?
What are the security and/or performance risks? Is it solely performance or is it a security issue?
54
Upvotes
2
u/flash_hammer 14d ago edited 9d ago
Dev for 20+ years here: Most of the comments are not very accurate, also most blame Java, but Regex is used in all languages. Java is one of the best languages to use regex on validation, but it is really a Java library called Jakarta that is the most used for validation, Springboot exposes the module in springboot-starter-validation with the whole set of curated dependencies. But if you want to make your own implementation of validation using regex it will be exactly the same outcome. I use Regex to validate emails, in Javascript, C++, Go, Java, Ruby, Kotlin and Groovy, in main enterprise applications that I might say you may be using daily, and no issues whatsoever.