in reply to Re^2: Regular Expression
in thread Regular Expression
It is my understanding that the code should match if and only if there is a non vowel character at the beginning of the string, an a followed by any number of characters except for other vowels, an e followed by any number of characters except for any number of vowels etc... and finally a u followed by any number of characters that are not other vowels at the end of the string. My questions: -The ^ anchor before the first set of brackets seems to me to say that the string must begin with a non vowel character in order to match. I tested this theory and as long as the vowels are in order the string can begin with a non vowel character. How does that work? -Why does the if statement not require brackets? -Why is the $ anchor necessary at the end? Wouldn't the regular expression do the same thing if it were left off? Thanks!!!#!/usr/bin/perl -w while (<>) { print if (/^[^aeiou]*a[^eiou]*e[^aiou]*i[^aeou]*o[^aeiu]*u[^aeio]*$/); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Regular Expression
by choroba (Cardinal) on Jun 21, 2012 at 06:13 UTC | |
|
Re^4: Regular Expression
by Athanasius (Archbishop) on Jun 21, 2012 at 06:18 UTC | |
|
Re^4: Regular Expression
by MidLifeXis (Monsignor) on Jun 21, 2012 at 12:42 UTC |