Next: , Previous: , Up: irregex   [Index]

50.4 Match objects

Function: irregex-search irx str
Function: irregex-search irx str start
Function: irregex-search irx str start past

Search for any instance of the pattern irx in str, optionally between the given range. If a match is found, return a match object, otherwise #f. Match objects can be used to query the selected substring or its submatches using the irregex-match-* procedures below. Examples:

(irregex-search "[a-z]+" "123abc456")
⇒ ... ; match object

(irregex-search "[a-z]+" "123456")
⇒ #f

(irregex-search "foobar" "abcFOOBARdef")
⇒ #f

(irregex-search (string->irregex "foobar"
⇒ ... ; match object

Matching follows the POSIX leftmost, longest semantics, when searching. That is, of all possible matches in the string, irregex-search will return the match at the first position (leftmost). If multiple matches are possible from that same first position, the longest match is returned.

Function: irregex-match irx str

Like irregex-search, but performs an anchored match against the beginning and end of the string, without searching.


(irregex-match '(w/nocase "foobar") "abcFOOBARdef")
⇒ #f

(irregex-match '(w/nocase "foobar") "FOOBAR")
⇒ ... ; match object
Function: irregex-match-substring match-obj
Function: irregex-match-substring match-obj index-or-name
Function: irregex-match-start-index match-obj index-or-name
Function: irregex-match-end-index match-obj index-or-name

Fetch the matched substring (or its start or end offset) at the given submatch index, or named submatch. The entire match is index 0, the first 1, etc. The default is index 0. Examples:

   (irregex-search "ciao" "hello ciao salut")
⇒ "ciao"

(let ((match (irregex-search "c(i(a(o)))"
                             "hello ciao salut")))
;;;                           01234567890123456

  (irregex-match-substring match)       ⇒ "ciao"
  (irregex-match-substring match 0)     ⇒ "ciao"
  (irregex-match-substring match 1)     ⇒ "iao"
  (irregex-match-substring match 2)     ⇒ "ao"
  (irregex-match-substring match 3)     ⇒ "o"

  (irregex-match-start-index match 0)   ⇒ 6
  (irregex-match-past-index match 0))   ⇒ 10

Next: , Previous: , Up: irregex   [Index]