$re = '/[\s\S]*?(\[[\d.]+])[\s\S]*/';
$str = '[Unreleased]
- bla bla bla
## [0.3.0] - 2016-12-13
- FIX This is an example fix
- FEATURE An example feature
I want to extract only the version numbers so I am left with:
[0.3.0]
- bla bla bla
[0.2.4]
- bla bla bla
[0.2.3]
- bla bla bla
';
$subst = "\1";
$result = preg_replace($re, $subst, $str, 1);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php