regex - Getting Index of First Non Alpha character in a string C# -
i'm trying split out string (at index) whenever find first non alpha or whitespace.
my regex rusty , trying find direction on getting work.
example: "payments received 08/14/2015 $0.00" string. , i'm able find first digit
string alphabet = string.empty; string digit = string.empty; int digitstartindex; match regexmatch = regex.match("payments received 08/14/2015 $0.00", "\\d"); digitstartindex = regexmatch.index; alphabet = line.substring(0, digitstartindex); digit = line.substring(digitstartindex);
the problem lies when string "amount period + $57.00" end "amount period + $"
how using regex in c#, if want include specific non-alphanumeric characters check such $ + -
?
edit: i'm looking output (variables alphabet , digit) in example above i'm struggling be.
"amount period"
"+ $57.00"
to split string way mention, use regular expression find initial alpha/space chars , rest.
var s = "payments received 08/14/2015 $0.00"; var re = new regex("^([a-z ]+)(.+)", regexoptions.ignorecase); var m = re.match(s); if (m.success) { console.writeline(m.groups[1]); console.writeline(m.groups[2]); }
the ^ important find characters @ start.
Comments
Post a Comment