using parse for 2Pet3:2 foo bar baz?

Started by TedWalther, November 05, 2007, 09:56:23 AM

Previous topic - Next topic

TedWalther

I have a file full of lines like this:



Gen1:30 blah blah blah

2Pet3:4 blah blah blah



I want to extract that first word, and split it up as follows:



Gen1:30 becomes ("Gen" "1" "30")

2Pet3:4 becomes ("2Pet" "3" "4")



I've played with parse a bit, but I'm flummoxed on this one.



I've made some progress with this:



(parse ((parse str " ") 0) ":")



Which yields ("Gen1" "30")



Is this a job for (regex)?



UPDATE: I played with regex and got what I needed.



(regex {^(.[[:alpha:]]+)(d+):(d+)}) mystring)



Ted
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence.  Nine months later, they left with a baby named newLISP.  The women of the ivory towers wept and wailed.  \"Abomination!\" they cried.

cormullion

#1
parse divides the text and 'consumes' the delimiters (or throws them away, if you like!). There's no delimiter between the "Gen" and the "1", so it would be difficult to use parse.



find-all is worth looking at too:


(dolist (v '({Gen1:30 blah blah blah} {2Pet3:4 blah blah blah}))
  (find-all {(.*?)(d+):(d+)} v (set 'b $1 'b $2 'v $3) 0)
  (println {Book } v { Chapter } c { Verse } c)
  )