[racket] Use regexps or something else?
On Sat, Jun 4, 2011 at 01:16, Eli Barzilay <eli at barzilay.org> wrote:
> [...]
> >
> > So then how useful are groups? Only to re-match them?
> > Like "(quack)\\1"...
>
> No, you get the groups results when you do a simple `regexp-match'.
> It just happens that `regexp-match*' was made to return the complete
> matches, it could have returned the subgroups too. Like I said, it
> could be added -- but every use that I've seen was one that got more
> benefit from restructuring the code differently. (As is in your
> case.)
>
I think I didn't understand well when I would use `regexp-match' with
groups.
It seems to return only the first match (as I expect) and the subgroups come
as the last elements of the list.
Since I want to find all the occurrences of a pattern, it seemed to
me `regexp-match*' was more appropriate.
>
>
> > > -> (read (open-input-string "3.129e+01"))
> > > 31.29
>
> Actually, I should have used the easier answer:
>
> (string->number "3.129e+01")
>
I think it's time for me to go to sleep... string->number would definitely
do, much better, thanks.
>
>
> > And is there a way to integrate that with reading the output from
> > the regexp? Something like a "scanf"?
>
> I'm not sure that I'm following that, but you could just do something
> like this:
>
> -> (map string->number (regexp-match* #rx"[^ ]+" "1.23 4e2"))
> '(1.23 400.0)
>
>
Well, that's not what I need, because I would lose the notion of a "line". I
want to do a "table filtering". The data is full of unuseful verbosity and I
intend to grab just the numbers and sort by the last column :D
For now I have (map parse-line (regexp.... )) where parse-line maps
string->number to a single line.
I can get along without removing columns, but anyway I don't see now a clean
way to filter-out some columns without writing dirty code :D
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110604/9da90c4f/attachment.html>