Dear team,

I am facing difficulties to validate the below format. I want regular expression needs to be satisfied with the below condtion.

$pattern = '/^\w[\w\s\.\%\-\(\)\[\]]*$/u'; 

$file_name = "(00)filename.jpg";


if(preg_match($pattern,$file_name)){
    echo "Pattern matched";
}else {
    echo "Pattern not matched";
}

I have tried several ways. But, the main problem is do not write the own pregmatch, instead need to modify the existing one which accepts the brackets().

Thanks,
Prem

Member Avatar

I have tried several ways. But, the main problem is do not write the own pregmatch, instead need to modify the existing one which accepts the brackets().

Sorry this is unclear. Can you explain further?

Brackets in where ? Beginning of file name with numbers inside brackets ? I'm not sure what you're actually trying. Below is the modified version of your pattern.

$pattern = '/^(\([0-9]\))?.\w[\w\s\.\%\-\(\)\[\]]*$/u';