I've been referring to http://www.regular-expressions.info/reference.html, however I just cannot understand how my regex unable to success.
function is_name($Argv){
$RegExp='/^[a-zA-Z]+[a-zA-Z()\. ]?+[a-zA-Z)]?+$/';
return preg_match($RegExp,$Argv)?$Argv:false;
}
I'm trying to make the name alphabet start, optional for some symbol or space at middle and ')' available at the end.
$testArray=array('L','D Luffy','Luffy','Monkey D. Luffy','Choppa(fiftyB)');
foreach($testArray as $key=>$value)
echo $auth->check->is_name($value); //output 'LLuffy'
it turns out only 'L' and 'Luffy' acceptable but not matching middle space which is optional. I can't opt out the middle optional as I have to match for 'L'.
update
problem solved, its the problem that i'm trying to do []?
however( I think ) the php matching ?+
before do []?
function is_name($Argv){
$RegExp='/^[a-zA-Z]+([a-zA-Z()\. ]?)+([a-zA-Z)]?)+$/';
return preg_match($RegExp,$Argv)?$Argv:false;
}