.net - Extract group of number from text -
having such text
above includes - add/remove member to/from nested group - 1.24.12 / 1.24.13
how create regular expression return 2 groups of 3 numbers have. expected result
1.24.12 1.24.13
i tried use such expression
private static regex mrdnumbers = new regex(@"((\d+.?){2,})+");
but doesn't work needed.
also, length of group can different, can
1.22 13.4.7 1.2.3.4 1.2.3.4.5 1.2.3.4.5.6
the problem .
in pattern. in regular expression language, .
character matches character (except in single-line mode), have escape \
character match periods.
try instead:
private static regex mrdnumbers = new regex(@"((\d+\.?){2,})+");
to capture matched numbers in list, might try this:
private regex mrdnumbers = new regex(@"(\d+?)(?:\.(\d+))+"); string input = "above includes - add/remove member to/from nested group - 1.24.12 / 1.24.13"; mrdnumbers.matches(input).cast<match>().dump(); var list = (from m in mrdnumbers.matches(input).cast<match>() select g in m.groups.cast<group>().skip(1) c in g.captures.cast<capture>() select c.value) .tolist(); // [ [ 1, 24, 12 ], [ 1, 24, 12 ] ]
or in fluent syntax:
var list = mrdnumbers.matches(input).cast<match>() .select(m => m.groups.cast<group>() .skip(1) .selectmany(g => g.captures.cast<capture>()) .select(c => c.value)) .tolist();
Comments
Post a Comment