Working with regular expressions
Regexps are textual expressions – or codes – that empower programmers to create highly customized parsers for strings. Pretend that your client has a document with thousands of customer comments in it and they only want to extract the serial numbers of defective products. If you have ever seen a product serial number, you will know that it is a unique identifier of a product, generally composed of letters and numbers – for example, XYW-001AB
. Well, using regexps, this task becomes easy, as it is possible to create a pattern that will fit that combination of letters and numbers for your client’s products exactly, making parsing a quick task.
At first, when you look at a regexp, it will look like a weird code or something hard to learn, but as you begin practicing and using it more, the patterns naturally start to look easier to read and write. We will go step by step from zero to build our knowledge about regexps.