Regex to mask Account number - works in regex101.com, but not in Qualtrics | XM Community
Skip to main content

I put together this regex code to look for digits that are either 8-15 digits long, or 17 digits long, regardless of if there’s words touching it. (Apparently I'm unable to paste other than as an image in this forum, my apologies)
image.pngI set up the logic like this because there was a 9 digit number that came through that I thought should have been caught in the SSN masking logic. On further investigation, Qualtrics' SSN logic requires spaces before and after the number to mask it:
image.pngMy code passes logic tests in regex101.com and works how I want it to, see below. But when I put the code to create a new topic in the sensitive data policy in Qualtrics, it says: "Regex is either invalid or too long". Why is Qualtrics not accepting this Regex?
image.pngimage.pngimage.pngimage.png

I don't think the regex engine used by Qualtrics supports lookahead or lookbehind.


Thanks! Do you know if there's another way to search to catch people that don't put spaces in their message (ie. like AccountNumber123456789?)?
If not, I can just do something similar that'll catch the number logic 8-15 or 17 digits long, and use spaces as the border, instead of the lookahead and lookbehind: \\b(\\d{8,15}|\\d{17})\\b


Try:
(\\b|\\D)(\\d{8,15}|\\d{17})(\\b|\\D)
By the way, to paste code like above, click on the paragraph mark to the left, click the quotes, then select Code Block.


Thank you! It looks like that code includes the first and last letter of the word if there's no space.
I played around with the code, and it gave me the idea of if that code includes the first and last character of the border, then I could modify it to use numbers as the border. But that was a bit messy; in the cases when people remember to put spaces, the buffer number on either end wasn't there, so the range was 7-14
I'll touch base with my team to figure out if we want to go with
(\\b|\\D)(\\d{8,15}|\\d{17})(\\b|\\D)
--or
\\b(\\d{8,15}|\\d{17})\\b
(Here's what I did for recording for the forum, but it's not a good solution. I am new at regex, so unsure about the implications of a open "or" statement, but it doesn't seem good)
image.png


Hmm I did further testing on
\\b(\\d{8,15}|\\d{17})\\b
It looks like Qualtrics doesn't recognize the logic in d{17}, which is odd since it works for your code:
(\\b|\\D)(\\d{8,15}|\\d{17})(\\b|\\D)


https://community.qualtrics.com/XMcommunity/discussion/comment/52283#Comment_52283I'm pretty sure Qualtrics supports non-capture groups, so you might try:
(?:\\b|\\D)(\\d{8,15}|\\d{17})(?:\\b|\\D)
You might need to break it into separate regex's:
\\b\\d{8,15}\\b
\\b\\d{17}\\b
...etc...



Thank you for your help. Updating below with the results of my testing:
It looks like Qualtrics' engine doesn't recognize the non-capture group either. I tested with the following two codes, and both times the previous and following letters were still captured.
(?:\\b|\\D)(\\d{8,15}|\\d{17})(?:\\b|\\D)
(?:\\b|\\D)(\\d{8,17})(?:\\b|\\D)
Another odd thing I noticed: Like you suggested, I put the 8-15 and 17 in two separate lines (below). With that, Qualtrics captured 7 digit long numbers too. I'm not sure why 7 digit numbers were captured since even in Qualtrics' own testing place it said it shouldn't be captured.
\\b\\d{17}\\b
\\b\\d{8,15}\\b
I tried a simpler code to just look at digits 8-17, and that also captured 7 digit number.
\\b\\d{8,17}\\b



Leave a Reply