Previous

Next


09. Metacharacters - The Character Class

  • The character class in regular expressions have some special characters of their own that are metacharacters when used inside the class!
  • For example, the dash character:
      -
            
    can be used inside a character class to specify a range, like this:
      [A-Z]
            
  • This character class would match a single character from "A", "B", "C", ..., "Z".
  • Similarly, the caret character:
      ^
            
    can be used to "negate" a character class, by placing it immediately after opening the class. For example, the character class:
      [^A-Z]
            
    would match a single character that was not from the range "A", "B", "C", ..., "Z".
  • Remember, special characters like these have this meaning only when used inside a character class, and only in the right way!
  • In a similar way, other metacharacters that we'll look at shortly are not metacharacters inside a character class - they behave like literal characters in between the square brackets!

Previous

Next

Andrew Hill

For LinuxSA Meeting, 21 November 2000