Finding Match for Alphabetic Range of Characters

I have been using regex for a long time to determine an assignee name based on the first initial of a students last name. Now, we are alpha-splitting workloads more granularly. Instead of simple single letter to single letter ranges, they are now up to 3 letter ranges. To my knowledge, this is where regex is not well suited because it doesn't directly support alphabetical range comparisons for full strings. Below is an examle of my current snippet, followed by the new alpha-split paramaters. Notice how with the new splits, the first is from 1 to 3 characters and the last group is from 3 to 1 characters. Any ideas on how to accomplish this?

{note: preview=yes; insert=no; color=none}
{formtext: name=enter name} <- type a first and last name to generate a split.
{name=`enter name`; trim=no}
{parts=splitregex(trim(name),"^\w+(\W+)"); trim=no}
Parts = {=parts}
{lastname=parts[count(parts)]; trim=no}
Last name={=lastname}
{initial=split(lastname, "")[1]; trim=left}
Initial={=initial}
{if: testregex(initial, "[a-e]", "i"); trim=left}
{assignee="Agent 1"; trim=left}
{elseif: testregex(initial, "[f-k]", "i"); trim=left}
{assignee="Agent 2"; trim=left}
{elseif: testregex(initial, "[l-q]", "i"); trim=left}
{assignee="Agent 3"; trim=left}
{elseif: testregex(initial, "[r-z]", "i"); trim=left}
{assignee="Agent 4"; trim=left}
{endif: trim=left}{endnote}{=assignee; trim=no}

{note: preview=yes; insert=no; color=none}
New Alpha-split of Last Names: a-eck: Agent 1

New Alpha-split of Last Names: ecl-lee: Agent 2

New Alpha-split of Last Names: lef-rob: Agent 3

New Alpha-split of Last Names: roc-z: Agent 4
{endnote}

Hi Brad,

If I am understanding this correctly, you can use the Text Blaze comparestrings() function, which compares strings lexicographically to see if another string comes before or after. This snippet is a simple example of how to accomplish this:

{lastname="Lee"}
{compareStr=lower(lastname)}

{if: comparestrings(compareStr, "eck") <= 0}
agent 1
{elseif: comparestrings(compareStr, "ecl") >= 0 and comparestrings(compareStr, "lee") <= 0}
agent 2
{elseif: comparestrings(compareStr, "lef") >= 0 and comparestrings(compareStr, "rob") <= 0}
agent 3
{elseif: comparestrings(compareStr, "roc") >= 0}
agent 4
{endif}

Let me know if this meets your needs!

Best regards,
Alexander

1 Like

This solution is absolutely perfect - THANK YOU!

1 Like