Regular expression

Regular expression

A regular expression is a useful construct found in many programming languages and frameworks that allows quick and flexible matching of strings of text. They are often used to search for parts of strings that match a certain pattern as opposed to a constant value. For example, a regular expression could be used to quickly determine if a paragraph of text contains a phone number in a format such as "(123) 123-1234", and extract the raw digits or replace it with some other text.

Regular expressions are a first-class datatype of JavaScript, so they are available for use throughout VXML applications. The following code example demonstrates the use of a regexp to determine if the user entered a four-digit number ending with "00".

<?xml version="1.0"?>
<vxml version="2.0">
  <form>
    <field name="myfield" type="digits">
      <prompt>
        Say or enter some digits.
      </prompt>
      <filled>
        <!-- The /^\d\d00$/ below is the regular expression -->
        <if cond="/^\d\d00$/.test(myfield)">
          You entered a four-digit number ending with 0 0.
        <else/>
          You entered some other kind of number.
        </if>
      </filled>
    </field>
  </form>
</vxml>

Regular expressions can also be used in application server code while generating VXML to be served to an IVR platform. For instance, PHP offers access to POSIX extended and Perl-compatible libraries for regular expressions in its standard library. A VXML application developer may need to use these functions to perform string matching similar to the above, validation of input from the user, or sanitization of values before insertion into a database or other backend.

Although the term "regular expression" has its roots in formal language theory and automata theory, the practical meaning has diverged from the formal meaning, which was defined as an expression of a regular language which is exactly the class of languages that can be accepted by deterministic finite automata. Modern regular expression libraries provided by JavaScript, Perl, Ruby, and many other programming languages allow for expression beyond the scope of this formal definition, with features such as grouped subexpressions or the ability to match on the result of an earlier subexpression, usually called backreferences. In spite of such features actually being NP-complete, most constructs for string patterns are still commonly called regular expressions, though they may also be colloquially referred to as patterns, regexes, regexps, or regexen.

Related links

Related terms

for "Regular expression"

Search Glossary

Term of the Day

The maxspeechtimeout property indicates the maximum duration of users speech input.
See also: Property, Tag, VoiceXML