Hi Joel,

I've been really frustrated too at how hard it is to do with parse
some very easy things for regexes. But for this kind job, parse is
great. You just have to embed a little code. This is what I did:

========== Code:

testdata: [
  "Manager: John Doe [123 Jones St] ([EMAIL PROTECTED])"
  "Employee: Jane Doe ([EMAIL PROTECTED])"
  "Trainee: Bobby Shaftoe [555 Silver Buckle Ln] (no email)"
  "Contractor: Mary Lamb [1111 Shepherd's Cove, Apt 7]"
  "Executive: Mary Mary Q. Contrary"
]

nonbrack: complement to bitset! "([])"

foreach item testdata [
  print item
  set [title name address email] copy/deep ["" "" "" ""]
  parse item [
    copy title to ":" skip  (trim title)
        copy name some nonbrack (trim name)
    any [
                "[" copy address to "]" skip (trim address) |
                "(" copy email to ")" skip (trim email)
        ]
  ]
  print join copy "^-" reduce [
    "{" title "} {" name "} {" address "} {" email "}"
  ]
]

========== Output:

Manager: John Doe [123 Jones St] ([EMAIL PROTECTED])
    {Manager} {John Doe} {123 Jones St} {[EMAIL PROTECTED]}
Employee: Jane Doe ([EMAIL PROTECTED])
    {Employee} {Jane Doe} {} {[EMAIL PROTECTED]}
Trainee: Bobby Shaftoe [555 Silver Buckle Ln] (no email)
    {Trainee} {Bobby Shaftoe} {555 Silver Buckle Ln} {no email}
Contractor: Mary Lamb [1111 Shepherd's Cove, Apt 7]
    {Contractor} {Mary Lamb} {1111 Shepherd's Cove, Apt 7} {}
Executive: Mary Mary Q. Contrary
    {Executive} {Mary Mary Q. Contrary} {} {}

==========

Just a couple of observations, though I'm sure it's obvious to you now:

If spaces are not important for delimiting fields, it's easier to use
PARSE than PARSE/ALL. If you want to trim the spaces, it's easier to
do that with TRIM than with PARSE itself. This code allows address and
email to be in either order, though that's probably not an advantage in
this case. It's not always necessary for the parse to "succeed" (return
true) in order for it to do what you want, so the BLANKS END you used
at the end of your rule probably wasn't necessary. I put a COPY/DEEP in
there as insurance to reduce the chances of code revisions introducing
a you-know-what kind of bug.


Keep on shippin',
Eric

Reply via email to