Pattern Matching in a file

  • Thread starter Thread starter lltaylor
  • Start date Start date
L

lltaylor

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
 
lltaylor said:
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
 
lltaylor said:
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.
 
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
 
Back
Top