OID Repository

www.oid-info.com
Regular expressions

Introduction

A regular expression is a character sequence that is an abbreviated definition of a set of strings. A string matches a regular expression if it is a member of the set described by the regular expression.

A regular expression is allowed to match anywhere within a string, unless the regular expression is explicitly anchored to the beginning (operator ^) or end (operator $) of the string.

 
Syntax

The following character sequences are recognized:

  • . matches any single character except newline
  • * (postfix) matches the previous expression zero, one or several times
  • + (postfix) matches the previous expression one or several times
    • [+] matches a "+" character (escape mechanism)
  • ? (postfix) matches the previous expression once or not at all
  • [  ] is a character set
    • ranges are denoted with a hyphen "-", as in [a-z]
    • an initial caret "^", as in [^0-9], complements the set (i.e., any character, except a lowercase letter from a to z, is accepted)
    • [[] matches a "[" character (escape mechanism)
    • []] matches a "]" character (escape mechanism)
  • ^ matches at beginning of line
  • $ matches at end of line
  • | (infix) alternative between two expressions
  • (  ) grouping of the enclosed expression
    • [(] matches a "(" character (escape mechanism)
    • [)] matches a ")" character (escape mechanism)
  • \ escapes special characters (i.e., ^.[$|*?{'):
    • \n matches a newline character
    • \. matches a dot "." character
    • \' matches a quote "'" character
    • \ cannot be escaped; to search for a backslash, use . to match any single character