Re: RegularExpressions
- From: "Kevin Spencer" <kevin@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 15 Jun 2006 19:03:15 -0400
Hi Serge,
I'm a little confused by your first and second example. You mentioned
something about not wanting the "first letter," and in your first example,
the lines with "BRE" in them all started with a single letter, but the other
lines did not, and in your second example, the lines did *not* start with a
first letter.
Be that as it may, I know you're chomping at the bit to use regular
expressions here, but in this case you don't want to use a Regular
Expression, even though it would be easy enough to write. Why? Because you
said "I have a huge file." Regular Expressions work with strings, and I
don't think that (1) you want to read a "huge file" into a single string,
and (2) use a regular expression on a string that large.
In fact, from what you've described about the size of the file, and wanting
to parse by line, your best bet (IMHO) would be to use a TextReader to read
the file one line at a time, and use String.IndexOf to evaluate whether or
not to include that line in your results. You could, for example, use a
single character array to read the lines into one at a time.
--
HTH,
Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist
A lifetime is made up of
Lots of short moments.
"Serge" <Serge@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A5EFF452-BB34-44CB-8477-7FAE1A3EC505@xxxxxxxxxxxxxxxx
Thats the thing...Im asking for a RegularExpression pattern. I know i can
just loop through all lines and use IndexOf and Substring...but I have a
huge
file and it will take forever. That is why Im asking if anyone has more
experience with RegularExpressions cause it is new to me.
Also yes, I said I want to extract all lines that start with BRE. So in my
example I want lines
BRE asdd asd dfddf
BRE errt ssdrr
BRE AAA asdd
Notice how I dont want the first character (or it could be more than 1
character) I just want to get the line that starts with BRE to the end of
the
line.
Thank you very much for your time
Serge
"Sanjib Biswas" wrote:
In your example, you said line starts with BRE but at the end you said
you
want lines 2,4, and 6. So I am assuming you mean to say line containing
BRE.
In that case after you have open the log file, read a line and do a
string
match to see whether that line contains BRE and if its true then store
that
line into an array or collection.
Regards
Sanjib
"Serge" <Serge@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:501E40F3-F275-457B-9956-440D1324C7A8@xxxxxxxxxxxxxxxx
Hello,
I have a log file that looks something like this
ABCDEF ddfs adasd
A BRE asdd asd dfddf
EROI DFIOU eeroo
B BRE errt ssdrr
AAA eIR DFDF
C BRE AAA asdd
All lines are seperated by NEWLINE (\r\n) I want to extract lines that
start
with BRE all the way to the end of the line and put them into a
collection
or
an array. So in this case I want line 2,4,6
Does any of you RegularExpressions gurus have an idea?
Thank you
.
- Follow-Ups:
- Re: RegularExpressions
- From: Serge
- Re: RegularExpressions
- References:
- Re: RegularExpressions
- From: Sanjib Biswas
- Re: RegularExpressions
- Prev by Date: Re: RegularExpressions
- Next by Date: Re: RegularExpressions
- Previous by thread: Re: RegularExpressions
- Next by thread: Re: RegularExpressions
- Index(es):
Relevant Pages
|