regexp
Happi
happi@REDACTED
Thu Aug 15 12:04:54 CEST 2002
This is perhaps not an answer to your question, but it looks to me like you
don't really need a regexp for your match.
If all your expressions are as easy as in your example you could use
string:tokens/2
1> String = "\\000\\005\\abc".
"\\000\\005\\abc"
2> string:tokens(String,"\\").
["000","005","abc"]
In Erlang I most often find it easier to write a recursive function that
parses the string than to try to come up with the right regular expression.
/Erik
org: Eric Conspiracy Secret Laboratories
I'm Happi, you should be happy!
Praeterea censeo "0xCA" scribere Erlang posse.
----- Original Message -----
From: "Tanja Godau" <eedtag@REDACTED>
> Hi,
>
> I've been using the regexp module to match various strings and parts of
strings.
> I would like to know how can I extract one or more variables from my
match.
>
> For example:
>
> I receive a string "\000\005\abc"
>
> I identify the string due to the leading three zeros, but I need to
extract
> the number "5" and the letters "abc" from the string.
>
> I've used regexp's with Perl and there I would bracket the parts I need
and be
> able to use them later as the variables $1, $2, etc. I'd like to know
how to
> do the same thing with Erlang.
>
> Something like this:
>
> String = "\000\005\abc",
> case regexp:match(String, "\\000.*\\00(.*)\\00(.*)") of
> {match,S,L} ->
> io:format("Number: ~p~n",[$1]), % this prints "Number: 5"
> io:format("Text: ~p~n",[$2]); % this prints "Text: abc"
> nomatch ->
> ...
>
> Question: How can I match a string and extract the variables I need in
Erlang?
>
> Thankyou
> Tanja Godau
>
>
More information about the erlang-questions
mailing list