I need help with getting the To: email address from the string below.
I know that this expression will get the value. System.Text.RegularExpressions.Regex.Match(CurrentMail.Body.ToString,”(?<=To:).*”).Value.Trim
But before getting the value must check that the value is between “To:” and “Cc:” and only get that value.
Cc: email@example.com, firstname.lastname@example.org
Please let me know how to solve this.
Hi @Sairam_RPA ,
Maybe the anchoring could be done by also keeping the Cc in the pattern :
FYI another approach
Sometimes cc could be
CC: or Cc:
How can I handle both here ?
We could Ignore case by adding the RegexOption :
Ignore case does not work.
The field name is CC: or Cc: . Can we check for those specific values ?
Something like below ?
(?<=To:)(.*?)(?=\nCc: or ?=\nCC: )
how about the following?
I see the below error message for this
it is working here, can you try again?
Regex.Match(strInput, "(?<=To:).*?(?=(Cc:|CC:|$))", RegexOptions.Multiline ).Value
Try removing the ?=\n from the pattern and check. Also, If you could provide the Input data sample with this variation we can confirm correctly the Regex to be used.
The regex works great ! @supermanPunch & @fernando_zuluaga.
Thanks a lot !!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.