To get a head start on introducing regular expressions , I’ll start with an example. It’s one that you’ve experienced hundreds of times. When you enter customer data online, many web forms ask you for an email address. To avoid an incorrectly typed address, an immediate validation makes sense. One way would be to split the string in parts (before and after the @ character), analyzing the positions of the dots and the number of characters after the last dot (that’s the top-level domain).
After a few ifs and loops, you’re almost done. Or you simply use a regular expression:
ˆ[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)* ...