<HTML> <HEAD> <!-- Created by texi2html 1.56k + clip patches and <A href="http://www.clip.dia.fi.upm.es/Software">lpdoc</A> from ciao.texi on 28 January 2007 --> <LINK rel="stylesheet" href="ciao.css" type="text/css"> <TITLE>The Ciao Prolog System - Pattern (regular expression) matching</TITLE> </HEAD> <BODY> Go to the <A HREF="ciao_1.html">first</A>, <A HREF="ciao_167.html">previous</A>, <A HREF="ciao_169.html">next</A>, <A HREF="ciao_241.html">last</A> section, <A HREF="ciao_toc.html">table of contents</A>. <P><HR><P> <H1><A NAME="SEC695" HREF="ciao_toc.html#TOC695">Pattern (regular expression) matching</A></H1> <P> <A NAME="IDX7846"></A> <P> <STRONG>Author(s):</STRONG> The CLIP Group. <P> <STRONG>Version:</STRONG> 1.10#7 (2006/4/26, 19:22:13 CEST) <P> <STRONG>Version of last change:</STRONG> 1.9#255 (2003/12/30, 23:32:38 CET) <P> This library provides facilities for matching strings and terms against <A NAME="IDX7847"></A> <A NAME="IDX7848"></A> <EM>patterns</EM> (i.e., <A NAME="IDX7849"></A> <A NAME="IDX7850"></A> <EM>regular expressions</EM>). <UL> <LI><A HREF="ciao_168.html#SEC696">Usage and interface (patterns)</A> <LI><A HREF="ciao_168.html#SEC697">Documentation on exports (patterns)</A> </UL> <H2><A NAME="SEC696" HREF="ciao_toc.html#TOC696">Usage and interface (<CODE>patterns</CODE>)</A></H2> <div class="cartouche"> <UL> <LI><STRONG>Library usage:</STRONG> <CODE>:- use_module(library(patterns)).</CODE> <LI><STRONG>Exports:</STRONG> <UL> <LI><EM>Predicates:</EM> <A NAME="IDX7851"></A> <CODE>match_pattern/2</CODE>, <A NAME="IDX7852"></A> <CODE>match_pattern/3</CODE>, <A NAME="IDX7853"></A> <CODE>case_insensitive_match/2</CODE>, <A NAME="IDX7854"></A> <CODE>letter_match/2</CODE>, <A NAME="IDX7855"></A> <CODE>match_pattern_pred/2</CODE>. <LI><EM>Regular Types:</EM> <A NAME="IDX7856"></A> <CODE>pattern/1</CODE>. </UL> <LI><STRONG>Other modules used:</STRONG> <UL> <LI><EM>System library modules:</EM> <A NAME="IDX7857"></A> <CODE>lists</CODE>. </UL> </UL> </div class="cartouche"> <H2><A NAME="SEC697" HREF="ciao_toc.html#TOC697">Documentation on exports (<CODE>patterns</CODE>)</A></H2> <P> <A NAME="IDX7858"></A> <A NAME="IDX7859"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>match_pattern/2:</B> <DD><A NAME="IDX7860"></A> <P> <STRONG>Usage:</STRONG> <CODE>match_pattern(Pattern, String)</CODE> <UL> <LI><EM>Description:</EM> Matches <CODE>String</CODE> against <CODE>Pattern</CODE>. For example, <CODE>match_pattern("*.pl","foo.pl")</CODE> succeeds. <LI><EM>The following properties should hold at call time:</EM> <CODE>Pattern</CODE> is a pattern to match against. (<CODE>patterns:pattern/1</CODE>) <CODE>String</CODE> is a string (a list of character codes). (<CODE>basic_props:string/1</CODE>) </UL> </DL> <P> <A NAME="IDX7861"></A> <A NAME="IDX7862"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>match_pattern/3:</B> <DD><A NAME="IDX7863"></A> <P> <STRONG>Usage:</STRONG> <CODE>match_pattern(Pattern, String, Tail)</CODE> <UL> <LI><EM>Description:</EM> Matches <CODE>String</CODE> against <CODE>Pattern</CODE>. <CODE>Tail</CODE> is the remainder of the string after the match. For example, <CODE>match_pattern("??*","foo.pl",Tail)</CODE> succeeds, instantiating <CODE>Tail</CODE> to <CODE>"o.pl"</CODE>. <LI><EM>The following properties should hold at call time:</EM> <CODE>Pattern</CODE> is a pattern to match against. (<CODE>patterns:pattern/1</CODE>) <CODE>String</CODE> is a string (a list of character codes). (<CODE>basic_props:string/1</CODE>) <CODE>Tail</CODE> is a string (a list of character codes). (<CODE>basic_props:string/1</CODE>) </UL> </DL> <P> <A NAME="IDX7864"></A> <A NAME="IDX7865"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>case_insensitive_match/2:</B> <DD><A NAME="IDX7866"></A> <P> <STRONG>Usage:</STRONG> <CODE>case_insensitive_match(Pred1, Pred2)</CODE> <UL> <LI><EM>Description:</EM> Tests if two predicates <CODE>Pred1</CODE> and <CODE>Pred2</CODE> match in a case-insensitive way. </UL> </DL> <P> <A NAME="IDX7867"></A> <A NAME="IDX7868"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>letter_match/2:</B> <DD><A NAME="IDX7869"></A> <P> <STRONG>Usage:</STRONG> <CODE>letter_match(X, Y)</CODE> <UL> <LI><EM>Description:</EM> True iff <CODE>X</CODE> and <CODE>Y</CODE> represents the same letter </UL> </DL> <P> <A NAME="IDX7870"></A> <A NAME="IDX7871"></A> <DL> <DT><span class="define">REGTYPE:</span> <B>pattern/1:</B> <DD><A NAME="IDX7872"></A> <P> Special characters for <CODE>Pattern</CODE> are: <DL COMPACT> <DT>* <DD> Matches any string, including the null string. <DT>? <DD> Matches any single character. <DT>[...] <DD> Matches any one of the enclosed characters. A pair of characters separated by a minus sign denotes a range; any character lexically between those two characters, inclusive, is matched. If the first character following the [ is a ^ then any character not enclosed is matched. No other character is special inside this construct. To include a ] in a character set, you must make it the first character. To include a `-', you must use it in a context where it cannot possibly indicate a range: that is, as the first character, or immediately after a range. <DT>| <DD> Specifies an alternative. Two patterns A and B with | in between form an expression that matches anything that either A or B will match. <DT>{...} <DD> Groups alternatives inside larger patterns. <DT>\ <DD> Quotes a special character (including itself). </DL> <P> <STRONG>Usage:</STRONG> <CODE>pattern(P)</CODE> <UL> <LI><EM>Description:</EM> <CODE>P</CODE> is a pattern to match against. </UL> </DL> <P> <A NAME="IDX7873"></A> <A NAME="IDX7874"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>match_pattern_pred/2:</B> <DD><A NAME="IDX7875"></A> <P> <STRONG>Usage:</STRONG> <CODE>match_pattern_pred(Pred1, Pred2)</CODE> <UL> <LI><EM>Description:</EM> Tests if two predicates <CODE>Pred1</CODE> and <CODE>Pred2</CODE> match using regular expressions. </UL> </DL> <P><HR><P> Go to the <A HREF="ciao_1.html">first</A>, <A HREF="ciao_167.html">previous</A>, <A HREF="ciao_169.html">next</A>, <A HREF="ciao_241.html">last</A> section, <A HREF="ciao_toc.html">table of contents</A>. </BODY> </HTML>