-1

the Given string :

/CN=RECIPIENTS/[email protected]

/CN=RECIPIENTS/[email protected]

OUTPUT :

 [email protected]

[email protected]

I m using this pattern but it is not working

^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$
Nizam35
  • 23
  • 5

2 Answers2

0

Try this . I try this according to the above sample. I you add some other sample string so it would be great to write strong regex.

Regex:

[a-zA-Z]+@[a-zA-Z]+[.][a-zA-Z]+

Output on regex101:

enter image description here

Usman
  • 1,983
  • 15
  • 28
0

One possible solution to retrieve email from your input string is,

1) Split your string by hyphen(-).

2) Take the 3 splitted string with index [2].

3) And remove digits from splitted string.

string input = "/CN=RECIPIENTS/[email protected]";

string output = new string(input.Split('-')[2].Where(x => !char.IsDigit(x)).ToArray());

Output:

enter image description here

Note: The above code only works for OP's provided input.

er-sho
  • 9,581
  • 2
  • 13
  • 26