Removing text and character after @ from a string

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



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 = "" />
<cfoutput>#REReplace(tx, "text(.*)", "text")#</cfoutput>
<cfset newtx = "#REReplace(tx, "text(.*)", "text")#">
<cfset textoutput = left(newtx, len(newtx) -1)>

You could omit using regex and do this:


email = "";

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


Working example here:

Or use listfirst function…

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

Thank you andreas, it works perfectly !!!

Thx you for the reply.

1 Like