Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: regex problem for inverse

1. ## regex problem for inverse

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

PHP Code:
``` '/^[a-zA-Z]{3}/'  ```
but how can i make it the direct contrary namley beyond this rule ?

• Originally Posted by zodehala
1- it will be start with [a-zA-Z] and total max 3 caharacters

PHP Code:
``` '/^[a-zA-Z]{3}/'  ```
but how can i make it the direct contrary namley beyond this rule ?
PHP Code:
``` /^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

• Originally Posted by zodehala
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).
Originally Posted by oesxyl
I'm not sure if more then 3, {3,} works this way in php, you must check.
{3,} means at least 3.

• Originally Posted by Inigoesdr
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

Edit:
... 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

• 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 ?

• Originally Posted by oesxyl
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?

• Originally Posted by zodehala
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 ?
PHP Code:
``` /^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

• Originally Posted by Inigoesdr
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)

• Originally Posted by zodehala
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,

PHP Code:
``` /^w{,3}/  ```
first time I understand that you want invers of:

because of:

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

• sorry we start ab initio ?

this is my codes
PHP Code:
``` 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 ?)

• PHP Code:
``` <?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

• very very tahnx

this is mine
PHP Code:
``` '/^[a-zA-Z]\w{0,3}\$/'  ```

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•