c# - Get a substring from a string using regex -


i have many strings in format:

fdg.sdfg.234fdsa.dsf_1.2.5.62.xml 23432ssdfsa_sadfsd_1.2.7.6.xml 3.3.3asdf_ddd_1.2.1.doc 

i number
from: fdg.sdfg.234fdsa.dsf_1.2.5.62.xml get: 1.2.5.62
from: f23432ssdfsa_sadfsd_1.2.7.6.xml get: 1.2.7.6
from: f3.3.3asdf_ddd_1.2.1.doc get: 1.2.1
etc

this code works:

string test = "4534534ghgggg_1.1.3.4.xml"; int = test.lastindexof('.'); int = test.lastindexof('_') + 1; console.writeline(test.substring(from,to - from)); 

but want know how can regex. ideas?

this code seems work long numbers looking preceded "_".

edited - final working result

        // fdg.sdfg.234fdsa.dsf_1.2.5.62.xml          // 23432ssdfsa_sadfsd_1.2.7.6.xml         // 3.3.3asdf_ddd_1.2.1.doc          string source = "fdg.sdfg.234fdsa.dsf_1.2.5.62.xml";          var match = regex.match(source, @"_[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)*").tostring().replace("_", "");         console.writeline(match);         console.readline(); 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -