A string or a precompiled regular expression object.
A string.
Bounding index designators of string .
A generalized boolean.
A generalized boolean.
The function
find-regexp-in-string
searches the string
string
for a match for the regular expression
pattern
. The index in
string
of the start of the first match is returned in
pos
, and the length of the match is
len
.
If
from-end
is
nil
(the default value) then the search starts at index
start
and ends at index
end
.
start
defaults to 0 and
end
defaults to
nil
. If
from-end
is true, then the search direction is reversed.
pattern
should be a precompiled regular expression object or a string. If
pattern
is a string then
find-regexp-in-string
first makes a precompiled regular expression object. This operation allocates, therefore if you need to repeatedly call
find-regexp-in-string
with the same pattern, it is better to call precompile-regexp once and pass its result, a precompiled regular expression object, as
pattern
.
case-sensitive
controls whether a string
pattern
is precompiled as a case sensitive or case insensitive search. A true value other than
:default
means a case sensitive search. The value
nil
means a case insensitive search. The default value of
case-sensitive
is
:default
which means that a string
pattern
is compiled with case sensitivity acording to the value of the Editor variable
DEFAULT-SEARCH-KIND
.
The regular expression syntax used by
find-regexp-in-string
is similar to that used by Emacs, as described in the "Regular expression syntax" section of the
LispWorks Editor User Guide
.
This form allocates several regular expression objects:
(loop with pos = 0
with len = 0
while pos
do (multiple-value-setq (pos len)
(find-regexp-in-string "[0,2,4,6,8]" "0123456789"
:start (+ pos len)))
when pos
do (format t "~&Match at pos ~D len ~D~%"
pos len))
This form does the same matching but allocates just one precompiled regular expression object:
(loop with pattern = (precompile-regexp "[0,2,4,6,8]")
with pos = 0
with len = 0
while pos
do (multiple-value-setq (pos len)
(find-regexp-in-string pattern "0123456789"
:start (+ pos len)))
when pos do (format t "~&Match at pos ~D len ~D~%"
pos len))