[erlang-questions] Erlang regex

Matteo <>
Wed May 21 22:13:45 CEST 2008


On Wed, May 21, 2008 at 10:02 PM, Igor Ribeiro Sucupira <>
wrote:

> On Wed, May 21, 2008 at 4:48 PM, Pablo Polvorin
> <> wrote:
> > Hello,
> > instead of regular expression, I would suggest to use pattern matching
> instead:
> > 1> A = <<"OK 01 xxxxxxxx\r\n">>.
> > <<"OK 01 xxxxxxxx\r\n">>
> > 2> <<"OK 01",X/binary>> = A.
>
> List equivalent would be something like:
> "OK 01 " ++ UnknownPart = Str
>
> The difference from my other suggestion would be that you're now
> checking if the strings starts with "OK 01 ", instead of just cropping
> the first 6 characters.



Hi,
only with OK 01 i've to read the next chars. In my other protocol i've got
other OK response but they are use for tracing the state of my app, and i
don't need to read the other chars.

M.Canato





>
>
> Igor.
>
> > <<"OK 01 xxxxxxxx\r\n">>
> > 3> X.
> > <<" xxxxxxxx\r\n">>
> >
> > besides that, if what you are parsing is some sort of network
> > protocol, you won't want to represent strings as lists(), but use
> > binaries like in the previous example.
> >
> >
> > 2008/5/21, Matteo <>:
> >> Hi to all,
> >> i'm a noob of erlang programming. I would like to have some infos about
> >> extracting a substring from a string....
> >> Or better, my situation is this:
> >>
> >> i have a string:
> >> str="OK 01 xxxxxxxx\r\n"); // where xxxxxxxx is a string that i dont
> know
> >> and every time change...
> >>
> >> and i need to extract the "xxxxxxx" into another string (str2 for
> exaple).
> >>
> >> Sorry for my english.
> >>
> >> Best regards
> >> M.Canato
> >>
> >
> >
> > --
> > --
> > pablo
> > http://ppolv.wordpress.com
> > ----
> > _______________________________________________
> > erlang-questions mailing list
> > 
> > http://www.erlang.org/mailman/listinfo/erlang-questions
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080521/64d4fd83/attachment.html>


More information about the erlang-questions mailing list