I spent the past few days thinking in a good challenge for this post. I came out with one that can be helpful to a lot of people.
Where I job we need to use the customer first name inside the chats sent.
This name can be extracted easily with regex combined with {site} or using CSS selectors
The issue is that since the name is selected arbitrary by the customer, sometimes it returns inappropriate or senseless names.
This is an old version of a snippet that we came with.
{if: extractregex({site:text}, "Customer Name
(.+)") == "Null [Last Name Not Specified]" OR extractregex({site:text}, "Customer Name
(.+)") == "[Last Name Not Specified]"}{name="there"}{elseif: testregex({site:text}, "Customer Name
\w*\s\w*")}{CxName=extractregex({site:text}, "Customer Name
(\w*)")}{CxLast=extractregex({site:text}, "Customer Name
\w*\s(\w*)")}{if: {=len(extractregex(CxName, "\w*"))} == 1 or {=len(extractregex(CxName, "\w*"))} == 2 or CxName == "" or {=isnumber(CxName)}}{if: CxLast == "" or {=isnumber(CxLast)} or {=len(extractregex(CxLast, "\w*"))} == 1 or {=len(extractregex(CxLast, "\w*"))} == 2}{name="there"}{elseif: testregex(CxLast, "^\D")}{name=extractregex({=proper(CxLast)}, "\D*")}{elseif: testregex(CxLast, "^\d*\D*")}{name=proper(extractregex(CxLast, "^\d*(\D*)"))}{endif}{elseif: testregex(CxName, "^\D")}{name=extractregex({=proper(CxName)}, "\D*")}{elseif: testregex(CxName, "^\d*\D*")}{name=proper(extractregex(CxName, "^\d*(\D*)"))}{endif}{else}{name="there"}{endif}{=name}
I know that @Juan_Murillo used a "wrong words" database to check if the extracted name is there first. Maybe he can share it with us, he has worked a lot more than me in this problem. But I think that it can be a good example to use the Regex function.