Regex to determine a Haiku?

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
alvinphp
Forum Contributor
Posts: 380
Joined: Wed Sep 21, 2005 11:47 am

Regex to determine a Haiku?

Post 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?
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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...
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Re: Regex to determine a Haiku?

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