I am trying to extract all strings that look like 12-15
from a parent string. This means all strings that have a dash in between two digits.
Using this answer as a basis, I tried the following:
<?php
$str = "34,56,67-90,45";
preg_match('/^(\d-\d)|(,\d-\d)|(\d-\d,)|(,\d-\d,)$/', $str, $output, PREG_OFFSET_CAPTURE);
echo print_r($output);
?>
This looks for any substring that looks a dash enclosed between digits, whether it has a comma before, after, or both, or none. When I run the PHP code, I get an empty array. On Regex101, when I test the regular expression, strings like 4-5,,,,,
seem to, and I'm not understanding why it's letting me add extra commas.
What's wrong with my regex that I get an empty array?