[erlang-questions] parsing text
Joe Armstrong
erlang@REDACTED
Sat May 1 12:03:27 CEST 2010
I think I'd have pretended that the input string were Erlang tokens.
I'd then use the Erlang tokeniser and pattern match the output, thusly:
1 > X="<B>Page Counter</B></TD><TD>4880</TD></TR>".
..
2 > hd([I || {integer,_,I} <- element(2, erl_scan:string(X))]).
4880
erl_scan:string is your friend :-)
/Joe
[I know it's cheating, so your don't have to tell me]
On Fri, Apr 30, 2010 at 9:49 PM, Wes James <comptekki@REDACTED> wrote:
> On Fri, Apr 30, 2010 at 1:46 PM, Colm Dougan <colm.dougan@REDACTED> wrote:
>> If you already found the offset of the start of the number then you
>> can use string:to_inetger (or more generally io_lib:fread) to extract
>> the number, regardless of it being variable length.
>>
>> Eshell V5.7.5 (abort with ^G)
>> 1> string:to_integer("4880</TD></TR>").
>> {4880,"</TD></TR>"}
>>
>> Eshell V5.7.5 (abort with ^G)
>> 1> io_lib:fread("<TD>~d</TD></TR>", "<TD>4880</TD></TR>").
>> {ok,[4880],[]}
>>
>> Colm
>
>
> Hey that's cool! Thx Colm!
>
> -wes
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>
More information about the erlang-questions
mailing list