2

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.

2 Answers 2

3

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?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. This solution is works. Sorry my english is not too good. I am working on an Imap/pop3 email client and I was a little problem to get attachment filenames , because it can contains accentuated letters.
1

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

1 Comment

Thanks help. Yes I wanted to find destination part of the string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.