Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: More Parsing questions

From: petr:krenzelok:trz:cz at: 6-Sep-2001 7:27

Stefan Falk wrote:
> Hi list, > as usual, I'm having parsin troubles. Here's what I'm trying to do: > > I have a regular text file containing names, with phone numbers, like this: > > "John Doe 5694" > "Jane Doe 0445-38352" > etc.. (I read it in using read/lines) > > what I want to do is to find all the lines that only have four digits in > them, the other ones should be ignored. > > So I tried this: > > >> data: "Ebba Grön 2345" > == "Ebba Grön 2345" > >> parse data [to "2345" to end] > == true > > And after that, I tried this: > > >> digit: charset "0123456789" > == make bitset! #{ > 000000000000FF03000000000000000000000000000000000000000000000000 > } > >> parse data [to 4 digit to end] > == false
I don't use parse too much, so I am no parse guru, but: data: "Ebba Grön 2345" digit: charset [#"0" - #"9"] ; but your solution is equivalent :-) ... alpha: complement digit parse/all data [some [alpha | digit]] but it will return true even in case of e.g. "1234-123454656" so you could turn it into sequence: parse/all data [some alpha some digit end] --------------- ->> data: "Ebba Grön 2345" == "Ebba Grön 2345" ->> parse/all data [some alpha some digit end] == true --------------- ->> data: "Ebba Grön 2345-1234556" == "Ebba Grön 2345-1234556" ->> parse/all data [some alpha some digit end] == false imo you can't use "to digit", as parser seems to me as matching engine, so you can skip only to known string, not some bitset, but I can be wrong. I don't know what is your exact data structure, but you could also: parse/all data " ", so if your data are space separated, you will end-up with following block: ->> parse/all data " " == ["Ebba" "Grön" "2345"] then, instead of using parse rules, some easy condition will work for you: if not found? find last parse/all data " " "-" [print "data OK"] hope-this-helps, -pekr-