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

    Join Date
    Jul 2011
    Posts
    17
    Rep Power
    0

    Need help targeting words starting with @ and no spaces/periods/commas after


    Hi I've used regex briefly in the past, not very often or complicated. I need help targeting words starting with @ and no spaces/periods/commas after

    I'm using preg_match_all to get all of these items but i believe my regex expression is the issue.

    So the string: "@hello devshed @hi"

    should only return in an array hello and hi.

    This is what i have now:

    Code:
    preg_match_all('/(@)(.*)[^\S]/', $string, $matches, PREG_SET_ORDER);
    Thanks!!
  2. #2
  3. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4124
    I've just helped someone in the PHP forum with a similar situation

    here's an excerpt:

    PHP Code:
    $str "Hello @kitty, i was talking to @northie about you. Thanks @sky.";

    $pattern  "/\@[A-Za-z0-9]+/";

    preg_match_all($pattern,$str,$matches);

    print_r($matches); 
    outputs:
    Code:
    Array
    (
        [0] => Array
            (
                [0] => @kitty
                [1] => @northie
                [2] => @sky
            )
    
    )
    Here's the full link: http://forums.devshed.com/php-develo...er-836590.html
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]

IMN logo majestic logo threadwatch logo seochat tools logo