user3855437
user3855437

Reputation: 13

Regex not detecting all occurrences

The following php code only detects some of the patterns

$re = "/([aeiou]+[bcdfghjklmnpqrstvwxyz]+[aeiou]+)/"; 
$str = "miniature"; 

preg_match_all($re, $str, $matches);
print_r($matches);

This shows the following results: 'inia' and 'ure'

(Array ( [0] => Array ( [0] => inia [1] => ure ) [1] => Array ( [0] => inia [1] => ure ) ))

Why is it not showing 'iatu' (any number of vowels followed by any numbers of consonant followed by any number of vowels)

How would I write the regex to give me all three results?
Thanks

Upvotes: 1

Views: 41

Answers (2)

Avinash Raj
Avinash Raj

Reputation: 174696

If you want iatu to be captured, then use a positive lookahead,

(?=([aeiou]+[bcdfghjklmnpqrstvwxyz]+[aeiou]+))

DEMO

Upvotes: 3

Braj
Braj

Reputation: 46841

Why is it not showing 'iatu'

because that is captured already by previous match inia

It returns two matches.

inia
ure

DEMO

Upvotes: 1

Related Questions