c# - Find a pattern into a string without space -


this question has answer here:

i'm looking way find , extract string matching pattern in string without space :

string regexpattern = @"[a-z]{4}\d{4}$";                    // ex : berf4787             string stringwithoutspace = "stringsampleberf4787withpattern";  string stringmatchpattern = ???         //i want befr4787 in variable 

you there. problem in pattern $ matches end of string. since in example "berf4787" located in middle of string should remove it:

string regexpattern = @"[a-z]{4}\d{4}";                    // ex : berf4787             string stringwithoutspace = "stringsampleberf4787withpattern"; 

if want match pattern in string can use regex.match method returns object of type match. matched value need use match.value property this:

string stringmatchpattern = regex.match(stringwithoutspace, regexpattern).value; 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -