First use the find function to find the @ character. So create a variable integer beforeAtInt and fill it with find($mystring, ‘@’). This will return a value of the location of that character. Then use substring to only get the string part before the @ by using the substring function. So create variable beforeAt and fill it with substring($mystring, $beforeAt) to give you that part. Now find the last space in that string by using findLast. So findlast($beforeAt, ‘ ‘). That gives you the character location of the space before the start of your mail address. Now do the same to find out if there is a space after the @ character. If none is found (result -1) it means that there is no text after it. I would double check if the last character is a dot (.) that could be there because it could mean the end of the sentence. You now have all the components to put all the parts together.
Regards,
Ronald