c# - String Equal to Regex Result? -


i have regex result capture in order use throughout code. such as, i'm using regex rid of specific part in string , i'd capture result in string variable.

is possible such thing? , how 1 go it?

input:

c:\users\documents\development\testing\11.0.25.10\w_11052_0_x.pts

expected result want store string:

c:\users\documents\development\testing\11.0.25.10\

regex pattern: ^(.*[\\])

of course can: groups property of system.text.regularexpressions.match object lets access match in form of string accessing value property of corresponding group.

for example, can capture value of expected output example:

string namestring = @"c:\users\documents\development\testing\11.0.25.10\w_11052_0_x.pts"; // note needed double slashes in pattern avoid "unmatched [" error string pathprefix = regex.match(namestring, @"^(.*[\\])").groups[1].value; console.writeline(pathprefix); 

the above prints

c:\users\documents\development\testing\11.0.25.10\ 

here demo on ideone.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -