Jump to content

php pregmatch find string contain hashtag only


gongpex
 Share

Recommended Posts

Hello everyone,

I have code:

$a = ' asasc #aaa cscv #ccc';

if (preg_match('/\#(\w+)/',$a, $matches)) {
            print_r($matches);
 }

this result are : 

Array ( [0] => #aaa [1] => aaa )

that result is not my expectation, my expectation if the result :

Array ( [0] => #aaa [1] => #ccc )

Q So in other word how to make so that preg_match return only the word start with # only.

please someone help me

Thanks

Link to comment
Share on other sites

  • 10 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...