You are looking at historical revision 4696 of this page. It may differ significantly from its current revision.

Introduction

A reader extension providing precompiled regular expression literals of the form <code>#/[A-Za-z0-9]+/</code>.

Examples

Using regular expression literals in the interpreter

Loading regex-literals also loads the regex unit and allows convenient use of regular expression literals as follows:

#;1> (use regex-literals)

#;2> #/[A-Za-z0-9]+/
#<regexp>

#;3> (string-match #/^(\d{2}):(\d{2})(..)/ "11:59pm")
("11:59pm" "11" "59" "pm")

#;4> (string-split-fields #/[^\s]+/ "the quick brown fox jumps over the lazy dog")
("the" "quick" "brown" "fox" "jumps" "over" "the" "lazy" "dog")

#;5> (string-split-fields #/[^\/]+/ "/path/to/file")
("path" "to" "file")

#;6> (string-substitute #/(\w+)\s+(\w+)/ "\\2, \\1" "John Smith")
"Smith, John"

Author

Arto Bendiken

Requires

Reader extensions

This egg installs a reader extension for #\/ that reads a regular expression literal as described below in read-regex-literal.

Note that there are some caveats to using reader extensions when compiling; for more details, refer to the relevant FAQ entry.

Input and output

read-regex-literal

[procedure] (read-regex-literal [PORT])

Reads a regular expression literal from PORT, which defaults to the value of (current-input-port). The literal is converted to a precompiled regular expression object using the (regexp) procedure provided by the regex unit.

License

 Copyright (c) 2006-2007 Arto Bendiken.
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to
 deal in the Software without restriction, including without limitation the
 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 sell copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:
 
 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 IN THE SOFTWARE.

Version history

1.0.0
Initial release of the regex-literals egg.