I am trying to get ONLY the numbers between the two brackets ([ ]) out of the string.
Here is my code:
$str = "[#123456] Some text";
preg_match('/^[#(?P<number>\w+)]/', $string, $matches);
// Returns 123456
echo $matches['number'];
Anyone able to help me out with this?
EDIT: I cleared up my question. I need to get ONLY the numbers between the brackets. The responses so far will give me numbers in the whole string.
If you need the numbers as well as the braces around them, you can use this regex:
Otherwise, use