Browse thread
[Caml-list] ocamllex, regular expression syntax
-
Stefan Heimann
- John Max Skaller
- David Brown
-
Pierre Weis
- Stefan Heimann
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Stefan Heimann <lists@s...> |
| Subject: | Re: Re: [Caml-list] ocamllex, regular expression syntax |
Hi,
On Fri, May 23, 2003 at 08:31:39AM +0200, Pierre Weis wrote:
> Hi,
>
> [...]
> > But the regular expression syntax in the Str module looks "normal"
to
> > me.
> >
> > Regular expressions like this
> >
> > "[^"\\]*(\\.[^"\\]*)*"
> >
> > are not easy to read,
>
> I suppose you did not try this, since it is not a legal regular
> expression. I guess you mean
>
> "[^\\"\\]*(\\.[^\\"\\]*)*"
>
> (Hence, the ``normal looking'' of those reg-exps does not imply
simple,
> clear, and natural syntax !)
no, the regular expression I mentioned is correct. The double quotes
do not enclose the regex but are part of it (maybe that's what
confused you):
stefan@kunz:~$ echo '"Hello \"World\"!"' | egrep
'"[^"\\]*(\\.[^"\\]*)*"'
"Hello \"World\"!"
stefan@kunz:~$ echo 'x' | egrep '"[^"\\]*(\\.[^"\\]*)*"'
stefan@kunz:~$
The single quotes just protect the string from shell expansion...
> > but with the ocamllex syntax it is even more
> > difficult:
> >
> > '"'[^'"''\\']*('\\'_[^'"''\\']*)*'"'
> >
> > (and harder to write).
>
> It is not so clear to me: the ' conventions are exactly those of the
> language (hence there is no need to \\ the " symbols), the _ gets
its
> "normal" meaning of ``whatever'' or ``catch all case'' pattern...
Normally you don't have to escape the " symbol with a backslash. Only
when you put them inside double quotes because you use the regular
expression as a normal string. But then it becomes really messy... In
ocaml's Str module syntax it looks like this:
let re = regexp "\"[^\"\\\\]*\\(\\\\.[^\"\\\\]*\\)*\""
> [...]
Bye,
Stefan
--
Stefan Heimann
http://www.stefanheimann.net :: personal website.
http://cvsshell.sf.net :: CvsShell, a console based cvs client.
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners