Removing text and character after @ from a string

I tried to remove the text after the @ (also the @ character should be removed)

example:
soemthing@googlesomehing.com
textsomthing@googlesomehing.com

Goal:
soemthing
textsomthing

The solution below is not optimal. As i don’t know how many character the e-mail address will have… anyone now a better solution ?

<cfset tx = "somthing@googlesomething.com" />
<cfoutput>#REReplace(tx, "text(.*)", "text")#</cfoutput>
<cfset newtx = "#REReplace(tx, "text(.*)", "text")#">
<cfset textoutput = left(newtx, len(newtx) -1)>
</br>
<cfoutput>#textoutput#</cfoutput>

You could omit using regex and do this:

<cfscript>

email = "soemthing@googlesomehing.com";

writeDump( email.listToArray("@").first() );

</cfscript>

Working example here: TryCF.com

Or use listfirst function…

<cfset tx = "somthing@googlesomething.com" />
<cfoutput>#listfirst(tx, "@")#</cfoutput>
1 Like

Thank you andreas, it works perfectly !!!

Thx you for the reply.

1 Like