Search code examples
phpregexregular-language

what is the regex for matching only #hashtags?


i am working on a social networking application and it have hash tag feature. i want to match all #tags but not #[[123:hashTag:rameez]] . i know reg-ex for both separately how can i do it in a single reg-ex?


Solution

  • Here is an example :

    $tweet = "this has a #hashtag a  #badhash-tag and a #goodhash_tag";
    
    preg_match_all("/(#\w+)/", $tweet, $matches);
    
    var_dump( $matches );