Jump to content

Matching heights, debug


Buyocat

Recommended Posts

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
Link to comment
Share on other sites

Maybe something like...

untested but it should work!

[code]<?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 />";
}
}

?>[/code]

me!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.