fork download
  1. <?php
  2. $string ="
  3. Text-Text
  4. Abc-123
  5. 123-Abc
  6. A2C-def4gk
  7. Ab-3
  8. Abc!-ajr4
  9. a-bc3-25aj
  10. a?c-b%";
  11.  
  12. $regex='~
  13. ^\w{3,} # at last three word characters at the beginning of the line
  14. - # a dash
  15. \w{3,}$ # three word characters at the end of the line
  16. ~xm'; # multiline and freespacing mode (for this explanation)
  17. preg_match_all($regex, $string, $matches);
  18. print_r($matches);
  19. ?>
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [0] => Text-Text
            [1] => Abc-123
            [2] => 123-Abc
            [3] => A2C-def4gk
        )

)