source: project/wiki/eggref/4/regex-case @ 12880

Last change on this file since 12880 was 12880, checked in by sjamaan, 12 years ago

Temporary hack to fix example sections in wiki eggdoc pages

File size: 3.1 KB
Line 
1[[tags: egg]]
2
3== regex-case
4
5[[toc:]]
6
7=== Description
8
9An easy to use {{case}} construct for matching regular expressions.
10
11=== Author
12
13[[felix winkelmann]]
14
15=== Requirements
16
17None
18
19=== Download
20
21[[http://www.call-with-current-continuation.org/eggs/regex-case.egg|regex-case.egg]]
22
23=== Documentation
24
25<macro>(regex-case EXPRESSION CLAUSE ...)</macro>
26
27Evaluates {{EXPRESSION}} and executes the body of the first {{CLAUSE}}
28that matches. Each {{CLAUSE}} should be of the form:
29
30  (REGEX LAMBDA-LIST BODY ...)
31
32The variables in {{LAMBDA-LIST}} are bound to the results of evaluating the expression
33
34  (string-match REGEX STRING)
35
36The last {{CLAUSE}} may also be
37
38  (else BODY ...)
39
40If no {{CLAUSE}} matches, the form returns an undefined result.
41
42=== Examples
43
44<examples><example>
45<init>(use regex-case)</init>
46<expr>
47(define (test x)
48  (regex-case x
49    ["[a-z]+" _ 'word]
50    ["[0-9]+" _ 'num]
51    [else 'nothing] ) )
52
53(test "42")
54</expr>
55<result>num</result>
56<expr>(test "hello")</expr>
57<result>word</result>
58<expr>(test "???")</expr>
59<result>nothing</result>
60</example></examples>
61
62<examples><example>
63<init>(use regex-case)</init>
64<expr>
65(regex-case "one23four"
66  ["[a-z]+([0-9]+).*" (all num) num] )
67</expr>
68<result>"23"</result>
69</example></examples>
70
71<examples><example>
72<init>(use regex-case)</init>
73<expr>
74(regex-case "http:www.foo.com/index.html"
75  ["([a-z]+):([a-z0-9.-]+)(/(.*))?" (_ . parts) parts])
76</expr>
77<result>("http" "www.foo.com" "/index.html" "index.html")</result>
78</example></examples>
79
80=== Changelog
81
82* 1.1 Adapted to new setup scheme.
83* 1.0 Initial release
84
85=== License
86
87  Copyright (c) 2003, Felix L. Winkelmann
88  All rights reserved.
89 
90  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
91  conditions are met:
92 
93    Redistributions of source code must retain the above copyright notice, this list of conditions and the following
94      disclaimer.
95    Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
96      disclaimer in the documentation and/or other materials provided with the distribution.
97    Neither the name of the author nor the names of its contributors may be used to endorse or promote
98      products derived from this software without specific prior written permission.
99 
100  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
101  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
102  AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
103  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
104  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
105  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
106  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
107  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
108  POSSIBILITY OF SUCH DAMAGE.
Note: See TracBrowser for help on using the repository browser.