Previous

Next


12. Metacharacters - Alternation and Grouping

  • You can provide alternation in regular expressions with the pipe character:
      |
            
  • Remember our regex to match "grey" or "gray"? We could also have done the regex this way:
      grey|gray
            
  • We can also use round brackets to provide logical grouping of characters to limit the scope of alternation. Thus, we could also write:
      gr(e|a)y
            
    to get another regex to search for "grey" or "gray"!
  • Yes, I'm lying about the brackets a bit. We'll get back to them later.

Previous

Next

Andrew Hill

For LinuxSA Meeting, 21 November 2000