c# - Regex Substring or Left Equivalent -


greetings beloved comrades.

i cannot figure out how accomplish following via regex.

i need take format number 201101234 , transform 11-0123401, digits 3 , 4 become digits left of dash, , remaining 5 digits inserted right of dash, followed hardcoded 01.

i've tried http://gskinner.com/regexr, syntax defeats me.

this answer, equivalent of substring regularexpression, sounds promising, can't parse correctly.

i can create sql function accomplish this, i'd rather not hammer server in order reformat strings.

thanks in advance.

you can try this:

var input = "201101234"; var output = regex.replace(input, @"^\d{2}(\d{2})(\d{5})$", "${1}-${2}01");  console.writeline(output); // 11-0123401 

this match:

  • two digits, followed by
  • two digits captured group 1, followed
  • five digits captured group 2

and return string replaces matched text

  • group 1, followed
  • a literal hyphen, followed
  • group 2, followed
  • a literal 01.

the start , end anchors ( ^ / $ ) ensure if input string not exactly match pattern, return original string.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -