Sublime Forum

Regular Expressions

#1

How do I search a four letter word containing every possible combination of 6 letters using regular expressions? I am completely new to this.

0 Likes

#2

Probably something like this (replace letters with your six letters): \b[aebsdt]{4}\b.

\b requires word boundaries before and after the searched letters.
[aebsdt] specifies a character group containing acceptable letters.
{4} says that you want 4 of what comes before it, so in this case 4 of any of the letters in [aebsdt].

1 Like

#3

Perfect, thank you !!

0 Likes

#4

Any chance of finding only four letters at the beginning or the end of a word ?

0 Likes

#5

\b[yourletters]\S*[yourletters]\b

0 Likes

#6

I’m not sure I’d use \S* if we are talking about beginning and/or end of word. I’d use \w* that represents word characters. \S* simply grabs non-white space chars, so things like (, ., etc. \w* is what you want as it will grab only word chars.

1 Like

#7

ok, thank you

0 Likes

#8

I think the answer is negative, but is there a way to get only one occurrence per combination when there are several ?

0 Likes

#9

I don’t think I understand the question. Can you elaborate? Maybe an example?

In general, regular expression will have its limits. Sometimes you may need to use it in combination with some scripted logic, but without an example, I am uncertain.

0 Likes

#10

I am using what you suggested on a huge list of words and i get the same combination of 4 letters (mbsh for example) on many words. Is it possible to see mbsh only once even if it occurs several times in the word list.

0 Likes

#11

What word list? Are you doing this in a script? If it is in a script, then yes, you can throw away duplicates of a match. But I still don’t understand your use case.

0 Likes

#12

No it’s not a script, I am simply searching a dictionary (650k words in a txt file) for 4 consonant combinations in words. (I just need the combinations as a type not the words). The same combination occurs hundreds of times. The regexp you gave me is doing wonderful, I am just trying to save time.

0 Likes

#13

Sounds like you may need to script what you are doing and return the results you are specifically looking for.

0 Likes