-1

the Given string :

/CN=RECIPIENTS/CN=GMAIL.ONMICROSOFT.COM-52001-KARNIK@GMAIL.COM213

/CN=RECIPIENTS/CN=GMAIL.ONMICROSOFT.COM-52001-AHMED@GMAIL.COM213

OUTPUT :

 KARNIK@GMAIL.COM

AHMED@GMAIL.COM

I m using this pattern but it is not working

^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$
Nizam35
  • 23
  • 5
  • please provide 2-3 more sample string input. – er-sho Mar 15 '19 at 06:04
  • 2
    Please [see here](https://stackoverflow.com/questions/46155/how-to-validate-an-email-address-in-javascript). The topic of writing a regex to cover an email address has already been well covered on this site. – Tim Biegeleisen Mar 15 '19 at 06:04
  • `@` is present only in `AHMED@GMAIL.COM` ? means no any occurence of `@` except email? – er-sho Mar 15 '19 at 06:26
  • Possible duplicate of [How to validate an email address in JavaScript?](https://stackoverflow.com/questions/46155/how-to-validate-an-email-address-in-javascript) – Michał Turczyn Mar 15 '19 at 06:42

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/CN=GMAIL.ONMICROSOFT.COM-52001-AHMED@GMAIL.COM213";

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