...

View Full Version : regex problem for inverse



zodehala
02-23-2008, 04:08 PM
1- it will be start with [a-zA-Z] and total max 3 caharacters


'/^[a-zA-Z]{3}/'


but how can i make it the direct contrary namley beyond this rule ?

oesxyl
02-23-2008, 04:25 PM
1- it will be start with [a-zA-Z] and total max 3 caharacters


'/^[a-zA-Z]{3}/'


but how can i make it the direct contrary namley beyond this rule ?



/^\W{3,}/


\W is inverse of \w what is same as [a-zA-Z].

I'm not sure if more then 3, {3,} works this way in php, you must check.

best regards

Inigoesdr
02-23-2008, 05:24 PM
but how can i make it the direct contrary namley beyond this rule ?
The circumflex goes inside of the brackets to say the opposite of ranges. So, '/[^a-zA-Z]{3}/' for example means anything other than a letter, exactly 3 times("123" for example would match).

I'm not sure if more then 3, {3,} works this way in php, you must check.
{3,} means at least 3.

oesxyl
02-23-2008, 05:29 PM
The circumflex goes inside of the brackets to say the opposite of ranges.

{3,} means at least 3.
yes, this is what I mean, I'm not sure about syntax, {3,} if work in php


... and total max 3 caharacters" => more the 3 or at least 4, :)

the OP could replace 3 with 4 if that he want, :)


best regards

zodehala
02-23-2008, 08:50 PM
it must supply following condition ?

1- it will start with between a and z (case sensibility is not important)
2- its lenght will be 3 (0<= x <=3)

how can i create it ?

Inigoesdr
02-23-2008, 09:00 PM
yes, this is what I mean, I'm not sure about syntax, {3,} if work in php

Yep, that would work in Perl-Compatible functions.

zodehala: Have you tried the regex posted by oesxyl?

oesxyl
02-23-2008, 09:10 PM
it must supply following condition ?

1- it will start with between a and z (case sensibility is not important)
2- its lenght will be 3 (0<= x <=3)

how can i create it ?



/^\w{,3}/


all of them letter?, can use \w or [a-zA-Z] as you allready use.

in general:
- {n,m} means between minim n occurance and maxim m.
- {,m} and {n,} one limit missing, semantic in both case is obvious, :)

Thank you Inigoesdr, :)

best regards

zodehala
02-23-2008, 09:13 PM
Yep, that would work in Perl-Compatible functions.

zodehala: Have you tried the regex posted by oesxyl?

according to that rules


zod is ok for me

but zodehala is ok too ( but its lenght is bigger than 3 for me it is not ok )

it must be lesser than 4

like i said before (0<= x <=3)

oesxyl
02-23-2008, 09:22 PM
according to that rules


zod is ok for me

but zodehala is ok too ( but its lenght is bigger than 3 for me it is not ok )

it must be lesser than 4

like i said before (0<= x <=3)

last one I postet it work,



/^\w{,3}/


first time I understand that you want invers of:


it will be start with [a-zA-Z] and total max 3 caharacters

because of:


but how can i make it the direct contrary namley beyond this rule ?

best regards

zodehala
02-23-2008, 10:52 PM
sorry we start ab initio ?

this is my codes

if (preg_match('/^[a-zA-Z]{0,3}/','zodehala')){
echo "OK";
}else{
echo "NOT";
}

this codes say OK but i want that if subject lenght is bigger than 3 it gives error (is it clear ?)

oesxyl
02-24-2008, 12:50 AM
<?php

$test = "zodehala";
for($i = 0; $i <= strlen($test); $i++){
$what = substr($test,0,$i);
if(preg_match("/^\w{0,3}$/",$what)){
echo "'".$what."' is OK<br/>";
}else{
echo "'".$what."' is NOT OK<br/>";
}
}

?>


best regards

zodehala
02-24-2008, 08:31 AM
very very tahnx

this is mine

'/^[a-zA-Z]\w{0,3}$/'



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum