c# - Reg Expression Error after combining -
format:
tb-string1-string2-year-numericdata1-numericdata1digitalways
examples per above format.
tb-testdata1-testdata2-2015-65789-3
this have tried for
var result = regex.match(testdata, @"\t\b-\s{2,5}\-\s{2,5}\-[\d{4}]\-\^[0-9]+$\-[\d]"); if (result.success) { return match; else { return nomatch; }
it throwing invalid argument exception.
here requirement.
first 2 letters “tb”. not case sensitive.
each items above separated “-”.
string1 --> characters z. not case sensitive. should between 2 5 characters.
string2 --> characters z. not case sensitive. should between 2 5 characters
year --> should 4 characters numeric data. year data. should +ve numbers only.
numericdata1 --> positive numeric data only. should between 2 10 characters.
numericdata1digitalways --> 1 digit numeric data between 0 8 only.
i have tried each parts individually. breaks when concatenate expression together.
thank help.
according conditions, regex not perfect. can use
var result = regex.match(testdata, @"[tt][bb]-([a-za-z]{2,5}-){2}\d{4}-\d{2,10}-[0-8]");
explanation:
\s
(all characters except space) should changed[a-za-z]
character between a-z , not case sensitive- ending
\d
should changed[0-8]
- also, have remove
^ , $
^[0-9]+$
since check beginning , ending of string
Comments
Post a Comment