- Scilab Help
- Strings
- ascii
- asciimat
- blanks
- char
- convstr
- emptystr
- evstr
- grep
- isalphanum
- isascii
- isdigit
- isletter
- isnum
- justify
- length
- part
- prettyprint
- regexp
- sci2exp
- strcat
- strchr
- strcmp
- strcspn
- strindex
- string
- strings
- stripblanks
- strncpy
- strrchr
- strrev
- strsplit
- strspn
- strstr
- strsubst
- strtod
- strtok
- tokenpos
- tokens
Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function
regexp
find a substring that matches the regular expression string
Syntax
[start] = regexp(input, pattern, [flag]) [start, final] = regexp(input, pattern, [flag]) [start, final, match] = regexp(input, pattern, [flag]) [start, final, match, foundString] = regexp(input, pattern, [flag])
Arguments
- input
a string.
- pattern
a character string (under the rules of regular expression).
- start
the starting index of each substring of
input
that matches the regular expression stringpattern
.- final
the ending index of each substring of
input
that matches the regular expression stringpattern
.- match
the text of each substring of
input
that matchespattern
.- foundString
the captured parenthesized
subpatterns
.- [flag]
'o'
for matching the pattern once.
Description
The rules of regular expression are similar to Perl language. For a quick start, see http://perldoc.perl.org/perlrequick.html. For a more in-depth tutorial on, see http://perldoc.perl.org/perlretut.html and for the reference page, see http://perldoc.perl.org/perlre.html
A difference with Perl is that matching a position but no character
(for example, with /^/
or
/(?=o)/
) is a successful match in Perl but not
in Scilab.
Examples
regexp('xabyabbbz','/ab*/','o') regexp('a!','/((((((((((a))))))))))\041/') regexp('ABCC','/^abc$/i') regexp('ABC','/ab|cd/i') [a b c]=regexp('XABYABBBZ','/ab*/i') piString="3.14" [a,b,c,piStringSplit]=regexp(piString,"/(\d+)\.(\d+)/") disp(piStringSplit(1)) disp(piStringSplit(2)) [a,b,c,d]=regexp('xabyabbbz','/ab(.*)b(.*)/') size(d) // get host name from URL myURL="http://www.scilab.org/download/"; [a,b,c,d]=regexp(myURL,'@^(?:http://)?([^/]+)@i') str='foobar: 2012'; // Using named subpatterns [a,b,c,d]=regexp(str,'/(?P<name>\w+): (?P<digit>\d+)/') d(1)=="foobar" d(2)=="2012"
See also
- strindex — search position of a character string in another string
History
Version | Description |
5.4.0 | A new output argument, foundString, has been added to retrieve subpatterns matches. |
Report an issue | ||
<< prettyprint | Strings | sci2exp >> |