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

[REBOL] Re: Newbie help: Parsing mobile email address

From: ingo:2b1 at: 11-Jun-2002 8:54

Hi Matthew Matthew Kim wrote: <..>
> Basically I'm trying to do this... > > Mobile Email Address: [4165551234--pcs--rogers--com] > > <Parsing algorithm> > > Result: > ~~~~~~~~~~~~~~~~~~~~~~~ > Area Code: 416 > Phone Number: 5551234
You could use parse ...
>> mea: [4165551234--pcs--rogers--com]
== [4165551234--pcs--rogers--com]
>> parse mea [ copy area 3 skip copy phone to "@" to end ]
== true
>> area
== "416"
>> phone
== "5551234" This rule would be happy to parse anything with an "@" symbol and at least 3 characters before it. If you want to check, if this is really a mobile phone number, you can change it like this:
>> digit: charset [ #"0" - #"9" ]
== make bitset! #{ 000000000000FF03000000000000000000000000000000000000000000000000 }
>> parse mea [ copy area2 3 digit copy phone2 6 8 digit "@" to end ]
== true
>> area2
== "416"
>> phone2
== "5551234" Now you can be sure, that there are only digits before the "@" and at least 3 for the area and 6 for the phone number, at most 8 for the phone number. I hope that helped, Ingo