Click here to Skip to main content
15,562,222 members
Home / Discussions / Regular Expressions
   

Regular Expressions

 
GeneralRe: A little help needed... Pin
Kornfeld Eliyahu Peter20-Mar-14 11:58
professionalKornfeld Eliyahu Peter20-Mar-14 11:58 
GeneralRe: A little help needed... Pin
Marco Bertschi20-Mar-14 12:21
professionalMarco Bertschi20-Mar-14 12:21 
GeneralRe: A little help needed... Pin
Kornfeld Eliyahu Peter20-Mar-14 12:28
professionalKornfeld Eliyahu Peter20-Mar-14 12:28 
GeneralRe: A little help needed... Pin
Marco Bertschi20-Mar-14 12:59
professionalMarco Bertschi20-Mar-14 12:59 
GeneralRe: A little help needed... Pin
Kornfeld Eliyahu Peter20-Mar-14 13:08
professionalKornfeld Eliyahu Peter20-Mar-14 13:08 
GeneralRe: A little help needed... Pin
Marco Bertschi20-Mar-14 13:14
professionalMarco Bertschi20-Mar-14 13:14 
JokeRe: A little help needed... Pin
Kornfeld Eliyahu Peter20-Mar-14 13:17
professionalKornfeld Eliyahu Peter20-Mar-14 13:17 
GeneralRe: A little help needed... Pin
Marco Bertschi20-Mar-14 21:23
professionalMarco Bertschi20-Mar-14 21:23 
GeneralRe: A little help needed... Pin
Kornfeld Eliyahu Peter20-Mar-14 23:42
professionalKornfeld Eliyahu Peter20-Mar-14 23:42 
AnswerRe: A little help needed... Pin
Marco Bertschi20-Mar-14 23:52
professionalMarco Bertschi20-Mar-14 23:52 
AnswerRe: A little help needed... Pin
Richard Deeming20-Mar-14 7:00
mveRichard Deeming20-Mar-14 7:00 
GeneralRe: A little help needed... Pin
Marco Bertschi20-Mar-14 8:02
professionalMarco Bertschi20-Mar-14 8:02 
AnswerRe: [Solved] Pin
Kenneth Haugland20-Mar-14 21:55
mvaKenneth Haugland20-Mar-14 21:55 
GeneralRe: [Solved] Pin
PIEBALDconsult25-Mar-14 13:30
professionalPIEBALDconsult25-Mar-14 13:30 
QuestionMATLAB Code Pin
Member 1068110218-Mar-14 20:02
Member 1068110218-Mar-14 20:02 
QuestionRe: MATLAB Code Pin
Richard Deeming19-Mar-14 3:04
mveRichard Deeming19-Mar-14 3:04 
AnswerRe: MATLAB Code Pin
Kornfeld Eliyahu Peter19-Mar-14 6:00
professionalKornfeld Eliyahu Peter19-Mar-14 6:00 
QuestionParsing ASCII-Only string Pin
Marco Bertschi6-Feb-14 23:54
professionalMarco Bertschi6-Feb-14 23:54 
AnswerRe: Parsing ASCII-Only string Pin
Richard Deeming7-Feb-14 2:36
mveRichard Deeming7-Feb-14 2:36 
GeneralRe: Parsing ASCII-Only string Pin
Marco Bertschi7-Feb-14 2:50
professionalMarco Bertschi7-Feb-14 2:50 
Richard,

thank you very much for your answer. I have developed the Regex a bit further, so it parses only matching strings, causing an InvalidOperationException in case the string contains any invalid characters. This behavior makes sense, since a hostname with removed characters may cause confusion.
I have also added a length maximum of 255 characters, and the string must have at least a single character.

C#
Regex regex = new Regex(@"(^[\40-\176]{1,254}$)");//Printable ASCII characters only
Match match = regex.Match(value);
if (match.Groups.Count == 2)
{
    host = match.Groups[1].Value;
}
else
{
    throw new InvalidOperationException(string.Format("The string {0} for host is misformatted. It may only contain printable US-ASCII characters.", value));
}


I am not fully convinced by your idea of iterating through the string - The RegEx makes the code easier to read, and easier to change if someone suddenly requires to allow special characters. In Addition to that, I fear a performance loss when iterating through the string.
Clean-up crew needed, grammar spill... - Nagy Vilmos

GeneralRe: Parsing ASCII-Only string Pin
Richard Deeming7-Feb-14 3:04
mveRichard Deeming7-Feb-14 3:04 
QuestionRe: Parsing ASCII-Only string Pin
Marco Bertschi7-Feb-14 3:08
professionalMarco Bertschi7-Feb-14 3:08 
AnswerRe: Parsing ASCII-Only string Pin
Richard Deeming7-Feb-14 3:14
mveRichard Deeming7-Feb-14 3:14 
GeneralRe: Parsing ASCII-Only string Pin
Marco Bertschi7-Feb-14 3:33
professionalMarco Bertschi7-Feb-14 3:33 
QuestionParsing a string with match groups Pin
Dominick Marciano23-Aug-13 10:47
professionalDominick Marciano23-Aug-13 10:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.