#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    5
    Rep Power
    0

    Regex noob with a question


    G'day everyone. I'm trying to wrap my head around regexes with PHP's preg_match function and have a problem.
    I wrote a small script to test out one aspect of it

    PHP Code:
    $test preg_match('/[^A-Z]/','football');

    if(!
    $test) {
        
        print(
    'Preg match Failed ...');
        
    } else {
        
        print(
    'Preg Match is a success, wooo Hoo');
        

    The way Im reading it with the ^ symbol where it is, it should return true which it is doing but even if I change the Capital f in Football it also returns true .... What am I missing here ?
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,072
    Rep Power
    9398

    Moved from PHP


    That's if the caret is outside a character set. Inside a character set, like as you have, it means either "any character except..." (if at the very beginning of the list) or "a literal caret" (if not).

    You're looking for
    Code:
    /^[A-Z]/

IMN logo majestic logo threadwatch logo seochat tools logo