point wrote:

I need some help with regulars...

how can I check if $var contains only "----" (minus) no metter how many??

Just as a point of interest, I compared the following 3 regular expressions:

/^-+$/, /[^-]/, /^([-]+)$/

I was going to suggest !preg_match("/[^-]/",$val), then realized it wouldn't

return false on an empty string, but I threw it in anyway. The code I used

follows the comparions. In just about ever case /^-+/ won. No surprised there,

just thought I find out how much different they are. I reordered the regex

array 3 times to make sure the array position wasn't biasing the results.

------

/^-+$/ AVG: 4.4089375120221E-05 seconds (363 sampled)

/[^-]/ AVG: 4.4289953219965E-05 seconds (322 sampled)

/^([-]+)$/ AVG: 4.4381050836472E-05 seconds (315 sampled)

-----------------------------------------3--

/^-+$/ AVG: 4.7261700218106E-05 seconds (324 sampled)

/[^-]/ AVG: 5.3900497155554E-05 seconds (353 sampled)

/^([-]+)$/ AVG: 5.3713196202328E-05 seconds (323 sampled)

--23333333333333333333-------

/^-+$/ AVG: 4.3738299402697E-05 seconds (290 sampled)

/[^-]/ AVG: 4.3901622804821E-05 seconds (351 sampled)

/^([-]+)$/ AVG: 4.5026909342051E-05 seconds (359 sampled)

--3------------------------------------------

/^-+$/ AVG: 4.3636065157915E-05 seconds (349 sampled)

/[^-]/ AVG: 4.4002504405861E-05 seconds (334 sampled)

/^([-]+)$/ AVG: 4.4881733434057E-05 seconds (317 sampled)

TESTINGTESTINGTESTING

/^-+$/ AVG: 4.2770132922486E-05 seconds (298 sampled)

/[^-]/ AVG: 4.4013239057577E-05 seconds (367 sampled)

/^([-]+)$/ AVG: 4.2876200889474E-05 seconds (335 sampled)

REORDER ARRAY

------

/^([-]+)$/ AVG: 4.5152124530541E-05 seconds (334 sampled)

/^-+$/ AVG: 4.4505271685899E-05 seconds (338 sampled)

/[^-]/ AVG: 4.5173778766539E-05 seconds (328 sampled)

-----------------------------------------3--

/^([-]+)$/ AVG: 5.4088808734965E-05 seconds (322 sampled)

/^-+$/ AVG: 4.7325738364301E-05 seconds (341 sampled)

/[^-]/ AVG: 5.387234051079E-05 seconds (337 sampled)

--23333333333333333333-------

/^([-]+)$/ AVG: 4.4645499606867E-05 seconds (331 sampled)

/^-+$/ AVG: 4.3906505752659E-05 seconds (318 sampled)

/[^-]/ AVG: 4.4383894004713E-05 seconds (351 sampled)

--3------------------------------------------

/^([-]+)$/ AVG: 4.4498060430799E-05 seconds (336 sampled)

/^-+$/ AVG: 4.3501577726225E-05 seconds (328 sampled)

/[^-]/ AVG: 4.3935364200955E-05 seconds (336 sampled)

TESTINGTESTINGTESTING

/^([-]+)$/ AVG: 4.281405290943E-05 seconds (326 sampled)

/^-+$/ AVG: 4.2799590290457E-05 seconds (345 sampled)

/[^-]/ AVG: 4.3385659307694E-05 seconds (329 sampled)

REORDER ARRAY

------

/[^-]/ AVG: 4.403849682176E-05 seconds (332 sampled)

/^([-]+)$/ AVG: 4.4901682613106E-05 seconds (329 sampled)

/^-+$/ AVG: 4.3864447107006E-05 seconds (339 sampled)

-----------------------------------------3--

/[^-]/ AVG: 5.405314904047E-05 seconds (339 sampled)

/^([-]+)$/ AVG: 5.3905426187718E-05 seconds (329 sampled)

/^-+$/ AVG: 4.7486948679729E-05 seconds (332 sampled)

--23333333333333333333-------

/[^-]/ AVG: 4.3712762685922E-05 seconds (325 sampled)

/^([-]+)$/ AVG: 4.420560948989E-05 seconds (323 sampled)

/^-+$/ AVG: 4.3457881970839E-05 seconds (352 sampled)

--3------------------------------------------

/[^-]/ AVG: 4.452014041889E-05 seconds (329 sampled)

/^([-]+)$/ AVG: 4.4954001013912E-05 seconds (335 sampled)

/^-+$/ AVG: 4.4005612532298E-05 seconds (336 sampled)

TESTINGTESTINGTESTING

/[^-]/ AVG: 4.2576365675663E-05 seconds (326 sampled)

/^([-]+)$/ AVG: 4.18363008818E-05 seconds (329 sampled)

/^-+$/ AVG: 4.1880469391311E-05 seconds (345 sampled)

---------------- START CODE

<plaintext>

<?php

$str = array("------", "-----------------------------------------3--",

"--23333333333333333333-------",

"--3------------------------------------------", "TESTINGTESTINGTESTING");

function getmicrotime(){

list($usec, $sec) = explode(" ",microtime());

return ((float)$usec + (float)$sec);

}

foreach($str as $strsample) {

$res = array(array("/[^-]/",0,0), array("/^([-]+)$/",0,0), array("/^-+$/",0,0));

for($i=0;$i<1000;++$i) {

$rnd = rand(0,2);

$time_start = getmicrotime();

preg_match($res[$rnd][0], $strsample);

$time_end = getmicrotime();

$res[$rnd][1]++;

$res[$rnd][2] += ($time_end - $time_start);

}

echo "\n\n ".$strsample."\n\n";

foreach($res as $val) {

echo " ".$val[0];

for($i=strlen($val[0]);$i<10;++$i) {

echo " ";

}

echo("\tAVG: ".($val[2] / $val[1])." seconds (".$val[1]." sampled)\n");

}

}

?>

---------------- END CODE

Shawn

--

Shawn Wilson

sh***@glassgiant.com http://www.glassgiant.com