By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,556 Members | 1,609 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,556 IT Pros & Developers. It's quick & easy.

Regex Question

P: n/a
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*(?<Add Charge>(\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
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
"WStoreyII" <WS*******@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com...
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*(?<Add Charge>(\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

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.