<?php $test_array = array( '', 'overfloW', ' oveяfloW', 'oveяfloW ', 'oveя floW', 'oveя fl_oW', ' oveя floW',); $pattern = '/^[\p{L}0-9](?:[\p{L}0-9 ]*[\p{L}0-9])?$/u';foreach ($test_array as $t) { echo "'$t' " , ( preg_match($pattern, $t) ? 'matches' : 'doesn\'t match' ), ' the pattern' , PHP_EOL;}
Standard input is empty
'' 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
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!