0

I have a String, which contains a list of mail addresses like so:

Dim address1 As String = """Merkel, Angela"" <[email protected]>, ""Peter Altmeyer"" <[email protected]>"

what I'm trying to archieve is to separate the String at the comma. I figure I need Regexp.Split therefore, but I don't have a clue, what exactly I have to do to get the output array of

"Merkel, Angela" <[email protected]>
"Peter Altmeyer" <[email protected]>

I'm especially confused by the double quotation mark "" to escape the quotation mark. Is this also escaped like so in the regular expression?

3 Answers 3

1

You can simply do it with the String.Split method, by including the ">" in the separator (">, "); however the ">" will be missing from the result and will have to re-add it.

With Regex you can do it as follows:

Dim parts() As String = Regex.Split(address1, "(?<=>),\s")

Here I am using the Regex pattern

(?<=prefix)find

which finds a position following a prefix. The result does not include the prefix. Therefore only ", " is removed from the output and the ">" remains.

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

1 Comment

No, this would chunk up the first address like "Merkel and Angela" <[email protected]>
1

You can split on this RegEx: (?<=>),\s*?(?=""). It finds commas (with zero or more whitespaces after) preceded by a < and proceeded by a "".

Comments

0
Dim address1 As String = """Merkel, Angela"" <[email protected]>, ""Peter Altmeyer""     <[email protected]>"
Dim parts() As String = Regex.Split(address1, "(?<=>),\s*?(?="")")

Comments

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.