1 <?xml version="1.0" encoding="UTF-8"?>
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) INRIA -
6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at
10 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13 <refentry xmlns="http://docbook.org/ns/docbook"
14 xmlns:xlink="http://www.w3.org/1999/xlink"
15 xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml"
16 xmlns:mml="http://www.w3.org/1998/Math/MathML"
17 xmlns:db="http://docbook.org/ns/docbook"
18 xml:id="regexp" xml:lang="en">
20 <refname>regexp</refname>
22 find a substring that matches the regular expression string
26 <title>Calling Sequence</title>
28 [start] = regexp(input, pattern, [flag])
29 [start, end] = regexp(input, pattern, [flag])
30 [start, end, match] = regexp(input, pattern, [flag])
31 [start, end, match, foundString] = regexp(input, pattern, [flag])
35 <title>Arguments</title>
40 <para>a string.</para>
47 a character string (under the rules of regular expression).
55 the starting index of each substring of
56 <varname>input</varname> that matches the regular
57 expression string <varname>pattern</varname>.
65 the ending index of each substring of
66 <varname>input</varname> that matches the regular
67 expression string <varname>pattern</varname>.
75 the text of each substring of <varname>input</varname>
76 that matches <varname>pattern</varname>.
81 <term>foundString</term>
84 the captured parenthesized <literal>subpatterns</literal>.
92 <literal>'o'</literal> for matching the pattern once.
99 <title>Description</title>
101 The rules of regular expression are similar to Perl language. For a
103 <ulink url="http://perldoc.perl.org/perlrequick.html">http://perldoc.perl.org/perlrequick.html</ulink>.
104 For a more in-depth tutorial on, see
105 <ulink url="http://perldoc.perl.org/perlretut.html">http://perldoc.perl.org/perlretut.html</ulink>
106 and for the reference page, see
107 <ulink url="http://perldoc.perl.org/perlre.html">http://perldoc.perl.org/perlre.html</ulink>
110 A difference with Perl is that matching a position but no character
111 (for example, with <literal>/^/</literal> or
112 <literal>/(?=o)/</literal>) is a successful match in Perl but not
117 <title>Examples</title>
118 <programlisting role="example"><![CDATA[
119 regexp('xabyabbbz','/ab*/','o')
120 regexp('a!','/((((((((((a))))))))))\041/')
121 regexp('ABCC','/^abc$/i')
122 regexp('ABC','/ab|cd/i')
123 [a b c]=regexp('XABYABBBZ','/ab*/i')
126 [a,b,c,piStringSplit]=regexp(piString,"/(\d+)\.(\d+)/")
127 disp(piStringSplit(1))
128 disp(piStringSplit(2))
130 [a,b,c,d]=regexp('xabyabbbz','/ab(.*)b(.*)/')
133 // get host name from URL
134 myURL="http://www.scilab.org/download/";
135 [a,b,c,d]=regexp(myURL,'@^(?:http://)?([^/]+)@i')
138 // Using named subpatterns
139 [a,b,c,d]=regexp(str,'/(?P<name>\w+): (?P<digit>\d+)/')
145 <refsection role="see also">
146 <title>See Also</title>
147 <simplelist type="inline">
149 <link linkend="strindex">strindex</link>
154 <title>History</title>
157 <revnumber>5.4.0</revnumber>
159 A new output argument, foundString, has been added to retrieve subpatterns matches.