[regex] How do I use a regular expression to match any string, but at least 3 characters?

I am not a regex expert, but my request is simple: I need to match any string that has at least 3 or more characters that are matching.

So for instance, we have the string "hello world" and matching it with the following:

"he" => false // only 2 characters
"hel" => true // 3 characters match found

This question is related to regex

The answer is


If you want to match starting from the beginning of the word, use:

\b\w{3,}

\b: word boundary

\w: word character

{3,}: three or more times for the word character


For .NET usage:

\p{L}{3,}


Try this .{3,} this will match any characher except new line (\n)


This is python regex, but it probably works in other languages that implement it, too.

I guess it depends on what you consider a character to be. If it's letters, numbers, and underscores:

\w{3,}

if just letters and digits:

[a-zA-Z0-9]{3,}

Python also has a regex method to return all matches from a string.

>>> import re
>>> re.findall(r'\w{3,}', 'This is a long string, yes it is.')
['This', 'long', 'string', 'yes']

I tried find similiar as topic first post.

For my needs I find this

http://answers.oreilly.com/topic/217-how-to-match-whole-words-with-a-regular-expression/

"\b[a-zA-Z0-9]{3}\b"

3 char words only "iokldöajf asd alkjwnkmd asd kja wwda da aij ednm <.jkakla "


You could try with simple 3 dots. refer to the code in perl below

$a =~ m /.../ #where $a is your string