I am pretty new to the use of preg_match. Searched a lot for an answer before posting this question. Found a lot of posts to get data based on youtube ID etc. But nothing as
One solution is:
\[#(\d+)\]
This matches the left square bracket and pound sign [#
, then captures one or more digits, then the closing right square bracket ]
.
You would use it like:
preg_match( '/\[#(\d+)\]/', '[#1234] Subject', $matches);
echo $matches[1]; // 1234
You can see it working in this demo.