More pattern matching examples
This section will present regular expressions that match more difficult patterns than the ones you have seen so far in this book. Just remember that regular expressions and pattern matching are practical subjects that you should learn by experimenting and sometimes failing, not by reading about them.
Note
If you are very careful with regular expressions in Go, you can easily read or change almost all the system files of a Unix system that are in plain text format. Just be extra careful when modifying system files!
A simple pattern matching example
The example of this section will improve the functionality of the countIP.go
utility, by developing a program that automatically detects the field with the IP address; therefore, it will not require the user to define the field of each log entry that contains the IP address. To make things simpler, the created program will only process the first IP address of each line: findIP.go
takes a single command-line argument,...