Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder
    Join Date
    Dec 2007
    Posts
    269
    Thanks
    28
    Thanked 0 Times in 0 Posts

    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 ?

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by zodehala View Post
    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

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by zodehala View Post
    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).
    Quote Originally Posted by oesxyl View Post
    I'm not sure if more then 3, {3,} works this way in php, you must check.
    {3,} means at least 3.
    Last edited by Inigoesdr; 02-23-2008 at 06:27 PM.

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Inigoesdr View Post
    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
    Last edited by oesxyl; 02-23-2008 at 06:33 PM.

  • #5
    Regular Coder
    Join Date
    Dec 2007
    Posts
    269
    Thanks
    28
    Thanked 0 Times in 0 Posts
    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 ?

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by oesxyl View Post
    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?
    Last edited by Inigoesdr; 02-23-2008 at 10:02 PM.

  • #7
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by zodehala View Post
    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

  • #8
    Regular Coder
    Join Date
    Dec 2007
    Posts
    269
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Inigoesdr View Post
    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)

  • #9
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by zodehala View Post
    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:

    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

  • #10
    Regular Coder
    Join Date
    Dec 2007
    Posts
    269
    Thanks
    28
    Thanked 0 Times in 0 Posts
    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 ?)

  • #11
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    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

  • #12
    Regular Coder
    Join Date
    Dec 2007
    Posts
    269
    Thanks
    28
    Thanked 0 Times in 0 Posts
    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
    •