I try to have a regex that has at least constraint in a string like "a string has at least two 'a' in it" and possibly "a string has at most three 'a'". Do you have any suggestion how to do it?

Thanks for any answer?

Something like this?

{M,N} Denotes the minimum M and the maximum N match count.

$string1 = "Hello World\n";
if ($string1 =~ m/l{1,2}/) 
{
    print "There exists a substring with at least 1";
    print "and at most 2 l's in $string1\n";
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.