RegEx question

V

Vai2000

Hi All, I have a file which has some lines starting with value 50.
xxx
xxx
50
vvvv
50
I have a solution by which I read line and filter the ones which I want...
Is there a way I can get it via Regular Expression,. Somehow this expression
is not working...please correct.

Regex reISA = new Regex(@"^[5][0]");

MatchCollection mGS = reISA.Matches(filecontent); // file read via
streamreader into a string content

foreach (Match m in mGS){

System.Diagnostics.Debug.WriteLine(m.Index+" "+m.Value);

}


TIA
 
G

Guest

You'll have to give examples as to the range of possible values and what you want to extract.
For instance, say
for "50abcde" I want to extract "abcde"
for "51abcde" ???
for "5034698ghijk" ???
for "5100euiyq" ???
for "0x32THISISINHEX" ???
for " 5 0 r21" ???

more info needed
 
V

Vai2000

Sorry for the poor explanation.
I want to grab records which start with 50

TIA

Beeeeeeeeeeeeves said:
if you can't provide more info I would suggest @"(?<=^50)[\s\S]*"


Vai2000 said:
Hi All, I have a file which has some lines starting with value 50.
xxx
xxx
5010100.....
vvvv
508744
I have a solution by which I read line and filter the ones which I want...
Is there a way I can get it via Regular Expression,. Somehow this expression
is not working...please correct.

Regex reISA = new Regex(@"^[5][0]");

MatchCollection mGS = reISA.Matches(filecontent); // file read via
streamreader into a string content

foreach (Match m in mGS){

System.Diagnostics.Debug.WriteLine(m.Index+" "+m.Value);

}


TIA
 
C

Chris R. Timmons

Sorry for the poor explanation.
I want to grab records which start with 50

You can use the System.String.StartsWith method.

Example:

string s = "50 Lines";
bool b = s.StartsWith("50");

If leading spaces are to be ignored, then simply trim the string:

string s = "50 Lines";
bool b = s.TrimStart(null).StartsWith("50");
 
V

Vai2000

Thanks Chris, Though as I mentioned in my post, I have the soln u
suggested,, was looking for only RegEx solution.

Thanks for comment though
 
B

BMermuys

Hi,
inline

Vai2000 said:
Hi All, I have a file which has some lines starting with value 50.
xxx
xxx
50
vvvv
50
I have a solution by which I read line and filter the ones which I want...
Is there a way I can get it via Regular Expression,. Somehow this expression
is not working...please correct.

Regex reISA = new Regex(@"^[5][0]");

try:
Regex reISA = new Regex(@"^50.*$", RegexOptions.Multiline);

HTH,
greetings
 
V

Vai2000

u are the man

Thanks

BMermuys said:
Hi,
inline

Vai2000 said:
Hi All, I have a file which has some lines starting with value 50.
xxx
xxx
50
vvvv
50
I have a solution by which I read line and filter the ones which I want...
Is there a way I can get it via Regular Expression,. Somehow this expression
is not working...please correct.

Regex reISA = new Regex(@"^[5][0]");

try:
Regex reISA = new Regex(@"^50.*$", RegexOptions.Multiline);

HTH,
greetings
MatchCollection mGS = reISA.Matches(filecontent); // file read via
streamreader into a string content

foreach (Match m in mGS){

System.Diagnostics.Debug.WriteLine(m.Index+" "+m.Value);

}


TIA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top