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}$
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}$
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:
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:
Note: The above code only works for OP's provided input.