Jump to content


Photo

Matching heights, debug


  • Please log in to reply
2 replies to this topic

#1 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 19 October 2006 - 05:36 PM

As in 6'2, I want to be find strings of the form:
6
6'2
6'22 (I suppose I'd like up to two decimal points)
6.2 (for those stubborn people who use odd punctuation)
6,2 (for those stubborn people who use odd punctuation)
6 2 (for those stubborn people who use odd punctuation)

I have the following expresssion
/^[1-9]?((.|,|\'|\s)([0-9]{1,2}))$/

However while it successfully matches the above it also matches
6666
666
66

Now I can see where perhaps three digits come from, though I'm not sure why it didn't demand something from the punctuation group, but I don't clueless as to how there could be 4 digits.

Any help plucking out these faulty matches would be much appreciated!

Buyo
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#2 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 20 October 2006 - 12:42 PM

Maybe something like...

untested but it should work!

<?php

$array = array ( 
'6', 
'6\'2', 
'6\'22', 
'6.2', 
'6,2', 
'6 2', 
'6 233', 
'77777', 
'7777'
);

foreach ( $array AS $test )
{
	if ( preg_match ( "/^([1-9]{1}+[\.\,\' ]{1}+[0-9]{1,2}|[1-9]{1})$/", $test ) )
	{
		echo $test . "<br />";
	}
}

?>

me!

#3 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 20 October 2006 - 12:47 PM

Maybe something like...

untested but it should work!


tested, and it works ;)
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users