Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cduce
cduce
Commits
82c839d4
Commit
82c839d4
authored
Oct 05, 2007
by
Pietro Abate
Browse files
[r2005-08-29 11:48:44 by afrisch] Add an example
Original author: afrisch Date: 2005-08-29 11:48:44+00:00
parent
624dec74
Changes
1
Hide whitespace changes
Inline
Side-by-side
web/ocaml.xml
View file @
82c839d4
...
...
@@ -1226,6 +1226,32 @@ Some features of XML Schema are not parsed, such as
</section>
<section
title=
"String regular expressions"
>
<p>
OCamlDuce supports regular expression types and patterns, not only
for sequences of XML elements, but also for strings. The following
example shows how to use regular expressions to split a string
of the form
<code>
name1=val1,...,namen=valn
</code>
with
<code>
n>0
</code>
into
a list of pairs
<code>
[ (name1,val1); ...; (namen,valn) ]
</code>
.
The
<code>
*?
</code>
operator in regular expressions means ``ungreedy
match'' (match the shortest possible subsequence). The last
pattern describes precisely strings which are not matched by
the other cases. It would be possible to replace it with
the wildcard
<code>
_
</code>
.
</p>
<sample>
<![CDATA[{{ON}}
let rec split (s : {{ String }}) =
match s with
| {{ [ n::_*? '=' v::_*? ',' rest::_* ] }} ->
(n,v)::(split rest)
| {{ [ n::_*? '=' v::_*? ] }} -> [ (n,v) ]
| {{ Any - [ _* '=' _* ] }} -> failwith "split"
]]>
</sample>
</section>
</box>
</page>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment