How to filter by string length

Hi there!

TLDR: I am trying to filter text strings and find only those that are 6 characters in length or less.

More info:

I figured that ‘filter’ using regex is probably the way to go.

From my research it seems that this regex formula: /^[a-z]{6}$/

Or ^[A-Za-z]{0,6}$

Should return any 6 character results but I can’t get it to return anything so far:

regex

I have tried quite a lot of other formulas I found on regular-expressions.info and stackoverflow but so far I am stumped.

The best I have been able to do so far is filter for words with 6 characters and longer [a-z]{6}

If you have any suggestions or leads I’d be very grateful.

Thank you!

p.s. If you know any good resources for learning how to work with strings that would also be great

^[A-Za-z]{0,6}$ works fine for me.

You can also use this in a Javascript transform:

var s = $(name);
return s.length;

And then filter on the length.

Are you sure you don’t have extra space characters or something else in the column?

There are some resources listed here:

Your hunch was correct, Some of the names have special characters and periods in them. I manually tested and the original formula does indeed work fine without them. I can’t figure out how to check for periods.
I believe I need to add . to the formula but my syntax must be wrong as I couldn’t get it to work .

Your examples were incredibly useful. The javascript solution works perfectly regardless of characters. I have saved it to my notes for reuse.

Thank you Andy!

Dot itsself matches any character. So ^.{0,6}$ may work. ALternatively try ^[\.A-Za-z]{0,6}$ . It depends on exactly what you do and don’t want to match.

We might add a regex testing sandbox in a future version, to make it easier to test regex expressions.

2 Likes