fork download
  1. <?php
  2.  
  3. $test_array = array(
  4. '',
  5. 'overfloW',
  6. ' oveяfloW',
  7. 'oveяfloW ',
  8. 'oveя floW',
  9. 'oveя fl_oW',
  10. ' oveя floW',
  11. );
  12.  
  13. $pattern = '/^[\p{L}0-9](?:[\p{L}0-9 ]*[\p{L}0-9])?$/u';
  14. foreach ($test_array as $t) {
  15. echo "'$t' " , (
  16. preg_match($pattern, $t)
  17. ? 'matches'
  18. : 'doesn\'t match'
  19. ), ' the pattern' , PHP_EOL;
  20. }
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
'' doesn't match the pattern
'overfloW' matches the pattern
' oveяfloW' doesn't match the pattern
'oveяfloW ' doesn't match the pattern
'oveя floW' matches the pattern
'oveя fl_oW' doesn't match the pattern
' oveя floW' doesn't match the pattern