Next: irregex sre repetition, Previous: irregex sre syntax, Up: irregex sre [Index]
The simplest SRE is a literal string, which matches that string exactly.
(irregex-search "needle" "hayneedlehay") ⇒ #<match>
By default the match is case–sensitive, though we can control this either with the compiler flags or local overrides:
(irregex-search "needle" "haynEEdlehay") ⇒ #f (irregex-search (irregex "needle" 'i) "haynEEdlehay") ⇒ #<match> (irregex-search '(w/nocase "needle") "haynEEdlehay") ⇒ #<match>
We can use w/case
to switch back to case–sensitivity inside a
w/nocase
or when the SRE was compiled with
case-insensitive
:
(irregex-search '(w/nocase "SMALL" (w/case "BIG")) "smallBIGsmall") ⇒ #<match> (irregex-search '(w/nocase "small" (w/case "big")) "smallBIGsmall") ⇒ #f
Of course, literal strings by themselves aren’t very interesting regular
expressions, so we want to be able to compose them. The most basic way
to do this is with the seq
operator (or its abbreviation
:
), which matches one or more patterns consecutively:
(irregex-search '(: "one" space "two" space "three") "one two three") ⇒ #<match>
The w/case
and w/nocase
operators allowed multiple
SREs in a sequence; other operators that take any number of
arguments (e.g. the repetition operators below) allow such implicit
sequences.
To match any one of a set of patterns we use the or
alternation
operator:
(irregex-search '(or "eeney" "meeney" "miney") "meeney") ⇒ #<match> (irregex-search '(or "eeney" "meeney" "miney") "moe") ⇒ #f