Limit Length of Variable Text

I use KM to grab text and generate names for files but sometimes have an issue where the name it generates is longer than 255 characters, meaning I get an error when I try to rename the file on MacOS. Is there a regex that can limit the number of all characters to 255? It's fine if it just cuts off. Thanks!

Yes, and it's pretty simple, too: .{255}

I think you will need:
(.{1,255})

{255} will require exactly 255 characters.

1 Like

Awesome! Silly question though, how do I apply that to a variable? Which action?

See Search using Regular Expression action

If you don't need RegEx for anything else, you could also use Substring of Variable or Clipboard action.

1 Like

Brilliant, I was using search and replace haha. Thanks so much!! Just set it to 250 because turns out 255 includes the extension, but it works :slight_smile:

You could just use the Substring of Variable action:

image

1 Like

Exactly.