We had a requirement to mask several attributes where the mask should always leave the least four characters visible like this
- String: 123456789
- Masked: *****6789
However, we ran into a scenario where a string could vary in length within the same attribute. This meant the standard masking option First "N" left more than four characters unmasked as the initial length increased, and the Last "N" option provided the opposite of the desired result:
- First 5 Masked:
- String: 123456789
- String: 1234567890
- Last 4 Masked
To meet our requirement, we used the Custom Masking option with the regular expression ".{4}$" and "Masked match part" set to false, like this in the UI:

The preview shows that the last four characters are left unmasked, and this can be directly validated with inputs of various lengths.
The JSON config would be like this:
"masking": {
"regexPattern": ".{4}$",
"maskMatched": false
}
The "4" in the curly braces determines how many characters are left unmasked and can be updated per requirement.
Hope this helps others.
------------------------------
Thanks,
Wes Corbin
Wex Inc
Portland ME
------------------------------