To load the module into Guile: (use-modules (regex spencer)) Examples/Tests ============== ;; compile a basic regular expression. (define a (regcomp "a")) (compiled-regex? a) ; => #t (compiled-regex? "a") ; => #f ;; match the compiled regular expression against a string. (define m (regexec a "bac")) ;; details of first and only match. (regmatch:start m 0) ; => 1 (regmatch:end m 0) ; => 2 ;; set limit to 0 to avoid allocating a match object. (regexec a "bac" 0 0) ; => #t ;; cflags extended, case-insensitive (define b (regcomp "a(b)" (logior REG_EXTENDED REG_ICASE))) ;; number of subexpressions. (re-nsub b) ; => 1 ;; match a string containing ASCII nul. (define n (regexec b "xy\0zab" REG_STARTEND)) (regmatch:start n 0) ; => 4 (regmatch:end n 0) ; => 6 (regmatch:start n 1) ; => 5 (regmatch:end n 1) ; => 6 ;; match only part of a string. (regexec b "abc" REG_STARTEND 1 3) ; => #f ;; omit submatch info (define b- (regcomp "a(b)" (logior REG_EXTENDED REG_ICASE REG_NOSUB))) (re-nsub b-) ; => -1 (regexec b- "xy\0zab" REG_STARTEND) ; => #t ;; compile a regex containing ASCII nul (define c (regcomp "a\0b" REG_PEND)) (define p (regexec c "a\0b" REG_STARTEND)) (regmatch:start p 0) ; => 0 (regmatch:end p 0) ; => 3 Reference ========= see also Spencer's man pages: rxspencer(3) and rxspencer(7) or regex(3) and regex(7). (compiled-regex? OBJ) Return `#t' if OBJ is a compiled Spencer regular expression, or `#f' otherwise. (regcomp STR FLAGS) Compile STR using Henry Spencer's regular repression library. FLAGS is an integer defaulting to zero. Its value should be specified with something like (logior REG_EXTENDED REG_ICASE). Recognised values are: REG_EXTENDED, REG_BASIC, REG_NOSPEC, REG_ICASE, REG_NOSUB, REG_NEWLINE, REG_PEND. For library documentation see the man pages: rxspencer(3) and rxspencer(5) or regex(3) and regex(5). (re-nsub RX) Return the number of parenthesized subexpressions in the compiled Spencer regular expression RX. The value will be -1 if the REG_NOSUB flag was specified when the repression was compiled. (regexec RX STR FLAGS LIMIT START END) Match the compiled Spencer regular expression RX against STR. FLAGS is an integer defaulting to zero. Its value should be specified with something like (logior REG_NOTBOL REG_NOTEOL). Recognised values are: REG_NOTBOL, REG_NOTEOL, REG_STARTEND. LIMIT is an integer specifying the maximum number of vector entries to return. Interesting values are -1 for any number (the default) and 0 to return `#t' on successful match instead of a vector. If FLAGS includes REG_STARTEND, the optional arguments START and END can be used to supply the offsets. START defaults to zero and END defaults to the string length. Hence, specifying REG_STARTEND while not supplying START and END will cause the entire string to be matched, including any embedded NULs. Return value: if match fails, `#f'. Otherwise, if RX was compiled with REG_NOSUB or LIMIT is 0, `#t'. Otherwise, a match object, see regmatch:start and regmatch:end. (regmatch:start OBJ N) Return the start position for the nth match in a match object returned by regexec. (regmatch:end OBJ N) Return the end position for the nth match in a match object returned by regexec.