[erlang-questions] Erlang regex

Igor Ribeiro Sucupira igorrs@REDACTED
Wed May 21 22:02:08 CEST 2008


On Wed, May 21, 2008 at 4:48 PM, Pablo Polvorin
<pablo.polvorin@REDACTED> 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.

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 <mcanato@REDACTED>:
>> 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
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list