regexp-position

Find the position of a regular expression inside a string.  If the regexp is not found, return #f, otherwise return a variable number of marks.

This function returns the index of the start of the regular expression in the big-string, or #f if the regular expression is not found.  As a second value, it returns the index of the end of the regular expression in the big-string (assuming it was found; otherwise there is no second value).  These values are called marks, and they come in pairs, a start-mark and an end-mark.  If there are groups in the regular expression, regexp-position will return an additional pair of marks (a start and an end) for each group.  If the group is matched, these marks will be integers; if the group is not matched, the marks will be #f.  So

regexp-position("This is a string", "is");

returns values(2, 4) and

regexp-position("This is a string", "(is)(.*)ing");

returns values(2, 16, 2, 4, 4, 13), while

regexp-position("This is a string", "(not found)(.*)ing");

returns #f.  Marks are always given relative to the start of big-string, not relative to the start: keyword.

Exported from

Arguments

big-stringAn instance of <string>.  The string to parse.
regexpAn instance of <string>.
start:An instance of <integer>.  Where to start parsing the string.  The default is 0.
end:An instance of <integer> or #f.  If defined, where to stop parsing the string.  The default is #f.
case-sensitive:An instance of <object>.  If true, match case in regexp while parsing.  The default is #f.

Values

regexp-startAn instance of type-union(<integer>, <false>).  If #f, a match was not found.  Otherwise, the index of the start of the match.
regexp-endAn instance of <integer>.  The index of the end of the match.  Not present if no match found.
#rest group-marksInstances of type-union(<integer>, <false>).  The indices of the start and end of each group’s match.  If a group is not matched, its corresponding index values will be #f, #f.  None of these values will be present if a match to the the regexp as a whole was not found.
Find the position of a regular expression inside a string.
Parsing a regexp is not cheap, so we cache the parsed regexps and only parse a string if we haven’t seen it before.
The class of sequences with elements that are characters.
The class of integers.
The class of all Dylan objects.