473,387 Members | 2,436 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,387 software developers and data experts.

simple regex question?

I am reading lines from a file that I need to breakdown.

while( ( read = FI.ReadLine() ) != null )
{
Console.WriteLine( read );

if( read.Contains( "<var>" ) )
{
Regex r = new Regex( @"^\<(\w+)>(\w+),(\d+),(\d+),(\d+)" );
string[] s = r.Split( read );

}
}
FI.Close();

The above works fine for "<var>StmtBal,7,60,19</var>".

But not for "<var>Acct#,5,0,1</var>" or
"<var>.........Description..........,30,16,6</var>".

How do I handle the "#", "*" etc and ".."?

Thanks,

Jerry


Jan 23 '07 #1
2 1050
Hi,
Could the "....description....." have a ',' in it? If so, you would
have to work backwards through the string? Other than that, you need to
know which extra symbols you will have.

HTH,
James.
Jerry wrote:
I am reading lines from a file that I need to breakdown.

while( ( read = FI.ReadLine() ) != null )
{
Console.WriteLine( read );

if( read.Contains( "<var>" ) )
{
Regex r = new Regex( @"^\<(\w+)>(\w+),(\d+),(\d+),(\d+)" );
string[] s = r.Split( read );

}
}
FI.Close();

The above works fine for "<var>StmtBal,7,60,19</var>".

But not for "<var>Acct#,5,0,1</var>" or
"<var>.........Description..........,30,16,6</var>".

How do I handle the "#", "*" etc and ".."?

Thanks,

Jerry
Jan 23 '07 #2
Lee
Probably replacing
(\w+),
with
([^,]+),
should work. It will match every non-, between the first and the
first ,.

--
// Lee Silver
// Information Concepts Inc.

I am reading lines from a file that I need to breakdown.

while( ( read = FI.ReadLine() ) != null )
{
Console.WriteLine( read );

if( read.Contains( "<var>" ) )
{
Regex r = new Regex( @"^\<(\w+)>(\w+),(\d+),(\d+),(\d+)" );
string[] s = r.Split( read );

}
}
FI.Close();

The above works fine for "<var>StmtBal,7,60,19</var>".

But not for "<var>Acct#,5,0,1</var>" or
"<var>.........Description..........,30,16,6</var>".

How do I handle the "#", "*" etc and ".."?

Thanks,

Jerry
Jan 23 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Howard Dean | last post by:
I have a string with several carriage returns in it. For example: "This is my test string" I wish to convert it to "This is my test string" (remove all carriage returns. Can someone tell me...
2
by: K. Shier | last post by:
my regex for matching phone #'s: \({0,1}(?<areacode>{3})\){0,1}( |-){0,1}(?<prefix>{3})( |-){0,1}(?<suffix>{4}) which i then .Replace to become: (${areacode}) ${prefix}-${suffix} question: ...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
20
by: Larry Woods | last post by:
I'm drawing a blank... What is the regular expression for search a string for NO occurances of a substring? Example: I want to find all lines that do NOT have the substing "image" in them. ...
5
by: Chris | last post by:
How Do I use the following auto-generated code from The Regulator? '------------------------------------------------------------------------------ ' <autogenerated> ' This code was generated...
7
by: Extremest | last post by:
I am using this regex. static Regex paranthesis = new Regex("(\\d*/\\d*)", RegexOptions.IgnoreCase); it should find everything between parenthesis that have some numbers onyl then a forward...
2
by: Warren | last post by:
Sorry to ask something so elementary, but I'm just not getting it. suppose I want to match the value of parameter b from a URL like http://www.abcd.com/?a=1&b=2&c=3 I can use this regex...
4
by: bg_ie | last post by:
I have the following Regex - oldString = @"C:\ta"; Regex regexEndsInBackslash = new Regex(oldString + @"\\", RegexOptions.Singleline | RegexOptions.IgnoreCase); Any ideas why none of the...
4
by: MaxMax | last post by:
I want to add a text to another text using regular expressions... An example before= "foo" after= "foobar" before= "one" after= "onebar" before = "" after = "bar"
2
by: Sin Jeong-hun | last post by:
I'm trying to replace \n with @(representing the actual new line character). Of course, \\n should not be replaced. What I'm trying to do is simply what the good-old printf does. For example, "\\n...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.