Page 1 of 1

Regex to determine a Haiku?

Posted: Mon Apr 09, 2007 12:44 am
by alvinphp
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?

Posted: Mon Apr 09, 2007 5:12 am
by Kieran Huggins
not likely - a haiku is based on syllables, which are difficult to match against character patterns.

Maybe the metaphone() function in PHP will help? It's a long shot...

Re: Regex to determine a Haiku?

Posted: Mon Apr 16, 2007 6:04 am
by stereofrog
alvinphp 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?
The question is in which language? For a language where each vowel builds a syllable, the solution is pretty straightforward

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";