I have a string.
I have to find a specific part of this string. I would like to use regex.
I need to find destination part in this name*=UTF-8''destination\r\n string. Which would be the good pattern?
Thanks.
To find name*=UTF-8''destination\r\n you can use something like
name\*=(.*)$
The part of the string after the = would then be in capturing group 1.
if you really want only the destination part, its probably more like this
name\*=UTF-8''(.*)$
* is a special character in regex (quantifier for 0 or more occurences) so you need to escape it \*
() brackets create a capture group (access like result.Groups[1]))
$ is an anchor that matches the end of the line. (your \r\n)
String Text_A = @"name*=UTF-8''destination
";
Regex A = new Regex(@"name\*=UTF-8''(.*)$");
var result = A.Match(Text_A);
Console.WriteLine(result.Groups[1]);
but your provided information is a bit sparse, can you explain a bit more and give more context?
I'm not entirely sure which part of your question is the string to be matched, but assuming your string is "name*=UTF-8"destination\r\n", you can use this Regex string:
@"name\*=UTF-8""(?<destination>.*)\r\n"
The "destination" field will be accessible from the Match object, i.e:
var regex = new Regex(@"name\*=UTF-8""(?<destination>.*)\r\n");
var match = regex.Match(test);
var destination = match.Groups["destination"].Value;
Depending on the context, you may be able to replace some other parts of the match string with more generic regular expression constructs (like . \w \s etc)
Cheers,
Simon