Sublime: Find words that are less than 4 characters

2

1

In Sublime, how can I use Grep to find words that are less 4 characters?

Searching around, I found this answer on how to use Grep to find words that are less 4 characters. It says to enter the following:

egrep -x '.{1,3}'

But this doesn't seem to work in Sublime. Even if I removed the egrep and -x prefix, it doesn't work.

Is there a trick to adapting Grep commands to work in Sublime?

big_smile

Posted 2019-09-03T15:16:40.090

Reputation: 331

Answers

4

About Sublime Text 3 RegExp engine

Sublime Text uses a propietary regex engine, unless the regular expression uses constructs that are unsupported by it, then Oniguruma will be used instead.

Author wrote about it at the Sublime Text forums:

Sublime Text build 3085 and newer contain a custom, non-backtracking regex engine for syntax highlighting only. It is heavily optimized for the type of matching that happens when lexing source files.

It is not open source, and does not contain some features present in Oniguruma, since it is a different style engine. Whenever possible, the Sublime Text regex engine will be used for a regex pattern in a .sublime-syntax or .tmLanguage file. If the regular expression uses constructs that are not supported by the new engine, Oniguruma will be used instead. We do not currently have any plans on removing the Oniguruma engine, so all existing .tmLanguage files will continue to be supported.

About .{1,3}

.{1,3} matches any string with 1 to 3 characters. That means that in the word HELLO it will match HEL and LO.

This is .{1,3} in action in ST3:

Sublime Text 3 RegExp

Variants

As it could not be what you are looking for, I see some variants that could help in case that your text has words separated by new-line.

^.{1,3}

To match the beginning of every word, if the word has, at least, 3 characters.

Example:

ONE
TO
TWO
THREE

will match: ONE, TWO, THR

.{1,3}$

To match the end of every word, if the word has, at least, 3 characters.

Example:

ONE
TO
TWO
THREE

will match: ONE, TWO, REE

^.{1,3}$

To match every word that has 1 to 3 characters.

Example:

ONE
TO
TWO
THREE

will match: ONE, TO, TWO

Ignacio Lago

Posted 2019-09-03T15:16:40.090

Reputation: 156