.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

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -