Regex Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a text table with the following columns

Minutes
Item#
Day
Date
Time
Number
CallTo
RateCode
RatePd
Feature
AirCharge
AddCharge
Total Charge

Here is my problem, not every record will have information for every column.
since this is a text table it is pushed together likes so

min item# day date time number callto ratecode ratepd feature airchg addchg
ttlchg
1 10 FRI 09/05 7:56PM Incomi Cl 5KNW DT M2MC 0.00 0.00 0.00
1 9 09/05 7:58PM Incomi CL 5KNW DT 0.00

so as you can see the first row has all the information and is easy to match
using the following pattern

"(?<Minutes>(\d+))\s*(?<Item>(\d+))\s*(?<Day>(MON|TUE|WED|THU|FRI|SAT))\s*(?<Date>(\d+/\d+))\s*(?<Time>(\d+:\d+\w+))\s*(?<Number>(\d+-\d+-\d+))\s*(?<Callto>(\w+\s\w+))\s*(?<RateCode>(5KNW|7ESM|FN4N|7RM6))\S*(?<RatePd>(DT|NW))\s*(?<Feautre>(M2MC|VM|CW))\s*(?<AirCharge>(\d+\.\d+))\s*(?<AddCharge>(\d+\.\d+))\s*(?<TotalCharge>(\d+\.\d+))"

but the second row does not have all of the information there so it is hard
to get the information that i need

So i was wondering if anyone knew of a way that i could make a pattern that
is similiar to the pattern that i have above but will skip over a group if
that info is not that and basically return a null value or something so that
i can get the data that i need from every row in this table. I have to add
this data to a database and this is the only format that i can get cingular
to give me this info in.

Thanks Again.

WStoreyII
 
WStoreyII,
I would make each group that is optional, optional using the ? qualifier
(zero or one matches).

So for just the Day group I would use:

(?<Day>(MON|TUE|WED|THU|FRI|SAT)?)

Which says that the Day named group needs to be zero or one of MON, TUE,
WED, THU, FRI, or SAT.

For the other groups that may or may not be there, I would do the same
thing.

My concern is the final 0.00 in your second sample: AirCharge, AddCharge, or
Total Charge?

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top