Regex to determine a Haiku?
Moderator: General Moderators
Regex to determine a Haiku?
Anyone know how to tell if a variable is a Haiku using a regular expression with the assumption that <br /> was used to seperate each line?
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
- stereofrog
- Forum Contributor
- Posts: 386
- Joined: Mon Dec 04, 2006 6:10 am
Re: Regex to determine a Haiku?
The question is in which language? For a language where each vowel builds a syllable, the solution is pretty straightforwardalvinphp wrote:Anyone know how to tell if a variable is a Haiku using a regular expression with the assumption that <br /> was used to seperate each line?
Code: Select all
$text = "
Furu ike ya
kawazu tobikomu
mizu no oto
";
$v = 'aeiou';
$haiku = "/
^
[^$v]*
([$v][^$v]*){5}
\n
[^$v]*
([$v][^$v]*){7}
\n
[^$v]*
([$v][^$v]*){5}
$
/x";
if(preg_match($haiku, $text))
print "ok";
else
print "NOT OK";