kurt jackson

kurt jackson

  • NA
  • 18
  • 0

RegEx Problem..

Feb 15 2010 3:47 AM

Hi folks,
Good day! I need some help on regex pattern to achieve this output: 123/1234567
Example:
Input: 1234567
Expected  Output: 123/1234567
Rule: 1. Get first the first 3 digit {123}
          2. Append / symbol {/}
         3. Concat the original Input {1234567}
         4. Expected output {123/1234567}
 
I have this patter in my code:
string input = "1234567";
string output = "";
regex rx = new regex(@"([\w]{1,3})([\w]{1,7})")
Match
match = null;
match = rx.match(input)
if (match.Groups.Count > 1)
   for (int i = 1; i < match.Groups.Count; i++)
      output +=
"/" + match.Groups[i].ToString();
 
but my output value is looks like this: 123/4567     which is wrong cause the expected output should looks like this: 123/1234567
I hope someone could help me in this problem. Thank you so much!
regards,
kurt
 

Answers (10)