Regular Expression

From TBwiki
Jump to: navigation, search

Contents

Introduction

Regular expressions, also referred to as regex or regexp, provides a concise and flexible means for matching strings of text, such as particular characters, words, or patterns of characters. A regular expression is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.

Regular expressions are extensively used in computing and is really powerful. You can think of regular expressions as wildcards on steroids. You are probably familiar with wildcard notations such as *.txt to find all text files in a file manager, the equivalent regex would be :

/.*\.txt$/

This section provides a quick reference.

Definition

Regular expressions is the term used for a codified method of searching invented or defined by the American mathematician Stephen Kleene.

POSIX definition

Traditional Unix regular expression syntax followed common conventions but often differed from tool to tool. The IEEE POSIX 1003.2 Basic Regular Expressions (BRE) standard (released alongside an alternative flavor called Extended Regular Expressions or ERE) was designed mostly for backward compatibility with the traditional (Simple Regular Expression) syntax but provided a common standard which has since been adopted as the default syntax of many Unix regular expression tools, though there is often some variation or additional features.

Perl-derivative

Perl has a more consistent and richer syntax than the POSIX basic (BRE) and extended (ERE) regular expression standards. An example of its consistency is that \ always escapes a non-alphanumeric character. Another example of functionality possible with Perl but not POSIX-compliant regular expressions is the concept of lazy quantification (see the next section).

Due largely to its expressive power, many other utilities and programming languages have adopted syntax similar to Perl's — for example, Java, JavaScript, PCRE, Python, Ruby, Microsoft's .NET Framework, and the W3C's XML Schema all use regular expression syntax similar to Perl's.


Toolpack and regular expressions

Toolpack Application:gateway makes use of Perl-derivative regular expressions for route matching and remapping (see CallRouting).

The Gateway application make uses of:

Note: Both PCRE and Ruby syntax are compatible (Perl-derivative).


Regular expression quick start guide


References

Regular Expression on Wikipedia

www.regular-expressions.info/quickstart.html


Personal tools