using parse for 2Pet3:2 foo bar baz?

For the Compleat Fan
Locked
TedWalther
Posts: 608
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC
Contact:

using parse for 2Pet3:2 foo bar baz?

Post by 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

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

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:

Code: Select all

(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)
  )

Locked