Regular Expression question

K

Kristian

Hi.

Can any one tell me why this code does not return what its supposed
to:

public string From(){
return POP3Message.Token( "From: (.*)" );
}

private static string Token( string _pat ){
Match match = Regex.Match( msg, _pat, RegexOptions.IgnoreCase );
if( match.Success ){
return match.ToString();
}else{
return "";
}
}

When I call the From method I get en empty string? In the Token method
the value of msg is passed earlier on in the code. The complete code
can be found here:

http://www.detandetfirma.dk/dotnet/POP3.cs
http://www.detandetfirma.dk/dotnet/RootMain.cs
http://www.detandetfirma.dk/dotnet/POP3Message.cs

Regards

Kristian
 
F

Francois Beaussier

Hi.

Can any one tell me why this code does not return what its supposed
to:
private static string Token( string _pat ){
Match match = Regex.Match( msg, _pat, RegexOptions.IgnoreCase );
if( match.Success ){
return match.ToString();

"return match.Value;" to get the matched line

or

"match.Groups[1].Value;" to get the text between the
brackets of your pattern "From: (.*)"

You might take into account that this pattern will return the entire
message as it will try to match as many character it can i.e. it will
not stop a the end of the line.
 
K

Kristian

Hi.

Can any one tell me why this code does not return what its supposed
to:

public string From(){
return POP3Message.Token( "From: (.*)" );
}

private static string Token( string _pat ){
Match match = Regex.Match( msg, _pat, RegexOptions.IgnoreCase );
if( match.Success ){
return match.ToString();
}else{
return "";
}
}

What would your advice be, how could I best solve that problem?
 

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