c# - Find a pattern into a string without space -
this question has answer here:
- reference - regex mean? 1 answer
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
Post a Comment