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

Pattern Matching in a file

P: n/a
Hello All,

I am writing a small program that allows me to scan inside a file and
extract data.

However I need to extract specific references within that document.
e.g. X100-DB1975

What is the best way to extract references of the type above - is it
using regular expressions.

Regular expressions are a bit of a dark art to me, could someone
provide me with a few pointers how to write a regular expression for a
string of the type.

ANNN-AANNNN

Where A = Number (0 - 9) and N = Alpha (A - Z)

Any help / pointers would be very much appreciated

Thanks

Lloyd
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"lltaylor" <ll**********@yahoo.com> wroite in
news:ac**************************@posting.google.c om...
Hello All,

I am writing a small program that allows me to scan inside a file and
extract data.

However I need to extract specific references within that document.
e.g. X100-DB1975

What is the best way to extract references of the type above - is it
using regular expressions.

Regular expressions are a bit of a dark art to me, could someone
provide me with a few pointers how to write a regular expression for a
string of the type.

ANNN-AANNNN

Where A = Number (0 - 9) and N = Alpha (A - Z)

Any help / pointers would be very much appreciated


Yes, regular expressions are probably the easiest way to do this.

I'd suggest using a tool like Expresso
(http://www.ultrapico.com/Expresso.htm); the "Resources" page on the same
site has some other links, too. I think you should find everything you need
there.

Niki
Nov 16 '05 #2

P: n/a

lltaylor wrote:
ANNN-AANNNN

Where A = Number (0 - 9) and N = Alpha (A - Z) but X100-DB1975
would be NAAA-NNAAAA, would'nt it?

However, this one matches NAAA-NNAAAA, like "X100-DB1975":
[A-Z][0-9]\{3\}-[A-Z]\{2\}[0-9]\{4\}
If you wanted it the other way, please tell me if you do not manage to edit
the expression yourself.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"lltaylor" <ll**********@yahoo.com> wrote in message
news:ac**************************@posting.google.c om... Hello All,

I am writing a small program that allows me to scan inside a file and
extract data.

However I need to extract specific references within that document.
e.g. X100-DB1975

What is the best way to extract references of the type above - is it
using regular expressions.

Regular expressions are a bit of a dark art to me, could someone
provide me with a few pointers how to write a regular expression for a
string of the type.

ANNN-AANNNN

Where A = Number (0 - 9) and N = Alpha (A - Z)

Any help / pointers would be very much appreciated

Thanks

Lloyd

Nov 16 '05 #3

P: n/a
Thanks to both of you,

Sorry Dennis it's been a long day - of course you are right I did mean
NAAA-NNAAAA, thanks for the reg ex - works perfect.

Niki - Thanks for the tip about espresso - very handy tool.

Lloyd

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.