<?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;
}