473,395 Members | 1,452 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Pattern Matching in a file

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
3 1873
"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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dariusz | last post by:
Despite looking at a number of tutorials in books and online examples on pattern matching - I can't quite get my head around it to work... so need some help. What I have now is a variable that...
8
by: gsv2com | last post by:
One of my weaknesses has always been pattern matching. Something I definitely need to study up on and maybe you guys can give me a pointer here. I'm looking to remove all of this code and just...
176
by: Thomas Reichelt | last post by:
Moin, short question: is there any language combining the syntax, flexibility and great programming experience of Python with static typing? Is there a project to add static typing to Python? ...
3
by: Greg Lindstrom | last post by:
Hello- I'm running Python 2.2.3 on Windows XP "Professional" and am reading a file wit 1 very long line of text (the line consists of multiple records with no cr/lf). What I would like to do is...
9
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # Matching string patterns # # Sometimes you want to know if a string is of # particular pattern. Let's say in your website # you have converted all images...
1
by: Henry | last post by:
I have a table that stores a list of zip codes using a varchar column type, and I need to perform some string prefix pattern matching search. Let's say that I have the columns: 94000-1235 94001...
2
by: Joecx | last post by:
Hi If I want to copy files using a pattern like: I want all files on a directory that start with 20050822 to be copied to a different directory. I can't get file.copy or copyfile to accept *.*...
10
by: bpontius | last post by:
The GES Algorithm A Surprisingly Simple Algorithm for Parallel Pattern Matching "Partially because the best algorithms presented in the literature are difficult to understand and to implement,...
5
by: olaufr | last post by:
Hi, I'd need to perform simple pattern matching within a string using a list of possible patterns. For example, I want to know if the substring starting at position n matches any of the string I...
5
by: pramodkh | last post by:
Hi All I am trying to match a pattern in a file and insert a line. If the pattern matches then insert a line before the matching pattern line. for example, I have the following content in a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.