Go to the previous, next section.
Searching means trying to match starting at successive positions
within a string. The function re_search does this.
Before calling re_search, you must compile your regular
expression. See section GNU Regular Expression Compiling.
Here is the function declaration:
int
re_search (struct re_pattern_buffer *pattern_buffer,
const char *string, const int size,
const int start, const int range,
struct re_registers *regs)
whose arguments are the same as those to re_match (see section GNU Matching) except that the two arguments start and range
replace re_match's argument start.
If range is positive, then re_search attempts a match
starting first at index start, then at @math{start + 1} if
that fails, and so on, up to @math{start + range}; if
range is negative, then it attempts a match starting first at
index start, then at @math{start -1} if that fails, and so
on.
If start is not between zero and size, then re_search
returns @math{-1}. When range is positive, re_search
adjusts range so that @math{start + range - 1} is
between zero and size, if necessary; that way it won't search
outside of string. Similarly, when range is negative,
re_search adjusts range so that @math{start +
range + 1} is between zero and size, if necessary.
If the fastmap field of pattern_buffer is zero,
re_search matches starting at consecutive positions; otherwise,
it uses fastmap to make the search more efficient.
See section Searching with Fastmaps.
If no match is found, re_search returns @math{-1}. If
a match is found, it returns the index where the match began. If an
internal error happens, it returns @math{-2}.
Go to the previous, next section.