Regex Help Please!

Hello fellow Blazers! Looking for some ideas as to how would you go about this.

I am in Salesforce Lightning. I want Regex to look at the last name of a student, then based on the first letter of the last name, I want the snippet I insert to populate a name in a field that assigns a task to that user. Example:

Student Name: Oscar de la Hoya

Return the name below based on alpha-split:
Online VA Students (A-F): Reggis Metayer
Online VA Students (G-O): Dahly Jimenez
Online VA Students (P-Z): Vien Le Delgado

In the above example, based on the students name, Regex would need to return the name “Dahly Jimenez” because she is the person who works with students whose last name starts with letters “G” through “O”.

If the student name was Jason L. Bateman, then the name needing to be returned would be “Reggis Metayer”.

The unknown factor is how many words or characters make up the students full name. Some have just first and last name while others have a middle initial, or a multi word last name like “Neil Degrasse-Tyson”.

Hope this makes sense. Thank you!
-Brad

Hey @Brad_Hedinger
Does the below snippet solve the purpose?

{formtext: name=name; default=Oscar de la Hoya}
{parts=splitregex(trim(name), "[\s-]")}
{lastname=parts[count(parts)]; trim=yes}
Last name={=lastname}
{initial=split(lastname, "")[1]; trim=left}
Initial={=initial}
{if: testregex(initial, "[a-f]", "i"); trim=left}
{assignee="Reggis Metayer"; trim=left}
{elseif: testregex(initial, "[g-o]", "i"); trim=left}
{assignee="Dahly Jimenez"; trim=left}
{else: trim=left}
{assignee="Vien Le Delgado"; trim=left}
{endif: trim=left}
Assignee={=assignee}

You can reduce the lines, i added more lines so that the logic is easy to understand.

1 Like

GLORIOUS! Thank you so much @VinodGubbala!!!

1 Like