This question already has a duplicate question (Duplicate question)
I'm not able to create a comment there, so i'm creating a new one.
The solution provided is very explanatory, but I am still not able to get a clear view of preg_match_all() .
I tried the following code
preg_match_all("/#+([a-zA-Z0-9_]+)/i","#test this is #php test",$matches);
var_dump($matches)
The result is
array(2) {
  [0]=>
  array(2) {
    [0]=>
    string(5) "#test"
    [1]=>
    string(4) "#php"
  }
  [1]=>
  array(2) {
    [0]=>
    string(4) "test"
    [1]=>
    string(3) "php"
  }
}
My understanding is that the regex will only select the string starting with '#' as per my code.
But in the result, the array contains the string with '#' and without '#'.
Please help me figure this out. What am I missing.
 
    