Regex
-
int counter = 0; ArrayList Numbers = new ArrayList(); Regex regex = new Regex(@"(.+);(.+);(.+)"); // only for 3 like "Gerald; 0650123456; Mike" ;-(((( Match matchit = regex.Match("Gerald; 0650123456; Sabine; Spech; 06761233333"); for (int i = 0; i < matchit.Groups.Count; i++) { Numbers.Add(matchit.Groups[i].Value); MessageBox.Show(Numbers[i].ToString().Trim()); }
hi the regex here don't work...i want to make it, that it works for: "Gerald; 0650123456; Sabine; Spech; 06761233333" result: Numbers[0] = Gerald; Numbers[1] = 0650123456; Numbers[2] = Sabine; Numbers[3] = Spech; Numbers[4] = 06761233333; and for: "Gerald; 0650123456; Mike" result: Numbers[0] = Gerald; Numbers[1] = 0650123456; Numbers[2] = Mike; the regex have to be independent from the length of the input string.... cu -
int counter = 0; ArrayList Numbers = new ArrayList(); Regex regex = new Regex(@"(.+);(.+);(.+)"); // only for 3 like "Gerald; 0650123456; Mike" ;-(((( Match matchit = regex.Match("Gerald; 0650123456; Sabine; Spech; 06761233333"); for (int i = 0; i < matchit.Groups.Count; i++) { Numbers.Add(matchit.Groups[i].Value); MessageBox.Show(Numbers[i].ToString().Trim()); }
hi the regex here don't work...i want to make it, that it works for: "Gerald; 0650123456; Sabine; Spech; 06761233333" result: Numbers[0] = Gerald; Numbers[1] = 0650123456; Numbers[2] = Sabine; Numbers[3] = Spech; Numbers[4] = 06761233333; and for: "Gerald; 0650123456; Mike" result: Numbers[0] = Gerald; Numbers[1] = 0650123456; Numbers[2] = Mike; the regex have to be independent from the length of the input string.... cuTry to use the following regex expression:
Regex regex = new Regex(@"[\w\d ]+;[\w\d ]+;[\w\d ]+");
the expression stands for:at least one word, digit or space followed by semicolon
and
at least one word, digit or space followed by semicolon
and
at least one word, digit or space.Let me know if it's ok Uri
-
Try to use the following regex expression:
Regex regex = new Regex(@"[\w\d ]+;[\w\d ]+;[\w\d ]+");
the expression stands for:at least one word, digit or space followed by semicolon
and
at least one word, digit or space followed by semicolon
and
at least one word, digit or space.Let me know if it's ok Uri
-
Hi, Maybe I didn't understand the requirements of your regex, because the regex I have provided returns a valid value for exectly 3 words or digit sets seperated by a comma. Could you provide me with more info about the results you are expecting to have ?
-
Hi, Maybe I didn't understand the requirements of your regex, because the regex I have provided returns a valid value for exectly 3 words or digit sets seperated by a comma. Could you provide me with more info about the results you are expecting to have ?
the regex should not only works for 3 words! for 9 words too... looks like that: "Gerald; 067612345; Sabine" or "Gerald; 067612345; Sabine; Mark; 065012233" than i want to have the names or numbers in an array: array[0] = Gerald array[1] = 067612345 array[2] = Sabine array[3] = Mark array[4] = 065012233 cu
-
the regex should not only works for 3 words! for 9 words too... looks like that: "Gerald; 067612345; Sabine" or "Gerald; 067612345; Sabine; Mark; 065012233" than i want to have the names or numbers in an array: array[0] = Gerald array[1] = 067612345 array[2] = Sabine array[3] = Mark array[4] = 065012233 cu
Hi, * use the following expr.
@"(?>\w|\d)+;?)"
* use theMatches
method and not theMatch
method as follows:ArrayList Numbers = new ArrayList(); Regex regex = new Regex(@"(?>\w|\d)+;?"); // only for 3 like "Gerald; 0650123456; Mike" ;-(((( MatchCollection collection = regex.Matches("Gerald; 0650123456; Sabine; Spech; 06761233333"); foreach(Match m in collection) { Console.WriteLine("**" + m.Value); }
-- modified at 12:12 Saturday 27th August, 2005 -
Hi, * use the following expr.
@"(?>\w|\d)+;?)"
* use theMatches
method and not theMatch
method as follows:ArrayList Numbers = new ArrayList(); Regex regex = new Regex(@"(?>\w|\d)+;?"); // only for 3 like "Gerald; 0650123456; Mike" ;-(((( MatchCollection collection = regex.Matches("Gerald; 0650123456; Sabine; Spech; 06761233333"); foreach(Match m in collection) { Console.WriteLine("**" + m.Value); }
-- modified at 12:12 Saturday 27th August, 2005 -
Hi, * use the following expr.
@"(?>\w|\d)+;?)"
* use theMatches
method and not theMatch
method as follows:ArrayList Numbers = new ArrayList(); Regex regex = new Regex(@"(?>\w|\d)+;?"); // only for 3 like "Gerald; 0650123456; Mike" ;-(((( MatchCollection collection = regex.Matches("Gerald; 0650123456; Sabine; Spech; 06761233333"); foreach(Match m in collection) { Console.WriteLine("**" + m.Value); }
-- modified at 12:12 Saturday 27th August, 2005 -
Yes :) Just remove the ;? from the regex expression i.e. use the following expression:
"(?>\w|\d)+"
. Hope it helps...hi, perfect, thats what i want;-) where can i learn regex? i am not that profi;-) here the code now:
int counter = 0; ArrayList Numbers = new ArrayList(); MatchCollection matchCollectionNamen; Regex regexNamen = new Regex(@"(?>\w|\d)+"); matchCollectionNamen = regexNamen.Matches("Gerald; 0676123456; 06503333543; Sabine"); foreach (Match m in matchCollectionNamen) { Numbers.Add(m.Value); MessageBox.Show(Numbers[counter].ToString()); counter++; }
do you have an idea how i can test for the first 4 digits when a number is recognized? only 0676, 0650, 0699, 0664 should be allowed for the first 4 digits... a second regex expression is needed? cu