tags:

views:

246

answers:

5

sorry 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

thansk in advance.

A: 

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

alejandrobog
`[.]` matches `.`, not any character.
wRAR
A: 

Assuming you're looking for any three characters from a specific search string, I'm not sure you could actually do that easily with a single simple regex (I'm assuming that case since the alternative is a simple RE like ... which you would have easily found elsewhere on SO).

I think your best bet would be to either use a series of individual substring searches:

For example:

needle = "hello"
num = 3
for i in 0 .. len(needle) - num:
    if haystack.find(substring(needle,i, num)):
        return FOUND
return NOTFOUND

Or construct an egrep-y string (hel|ell|llo) using the same method for generating a single RE.

needle = "hello"
num = 3
regex = ""
for i in 0 .. len(needle) - num:
    if regex != "":
        regex += "|"
    regex += substring(needle,i, num)
if haystack.find(regex):
    return FOUND
return NOTFOUND
paxdiablo
A: 

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

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

ujj
A: 

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']
Brendan Abel
Yeah, I totally answered a different question than the OP was asking. After reading Paxdiablo's solution it made sense.
Brendan Abel
A: 

For .NET usage:

\p{L}{3,}