Previous

Next


18. Metacharacters - Quantifiers

  • Consider the phone number example again, but this time forget the area code. We have a list of phone numbers, all that have been badly entered into a file that looks something like example03.txt:
      1234 5678
      4351-9876
      87547890
      8965  9887
      9885 - 9874
            
  • Now, how can we possibly write a regex to match all those phone numbers? Not only do all these phone numbers have different numbers in different positions, we can't even guarantee that they all have the same number of characters as spacers in between the numbers (or even that they have spacers!)
  • Fortunately, regular expressions have metacharacters that act as "quantifiers", and allow us to match varying amounts of the same thing.

Previous

Next

Andrew Hill

For LinuxSA Meeting, 21 November 2000