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

Last change on this file since 13306 was 13306, checked in by felix winkelmann, 11 years ago

added xlib page and removed download links

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