I want to check the filename extension if it's PDF, DOC or DOCX using : isMatch($filename, '(?i).(pdf|docx?)$') But it's always false Any idea
asked
Jerome Sablon
4 answers
2
With The Community commons Regex Test you can test case insensitive as well:
'(?i:^.*.(pdf|docx)$)'
answered
Andries Smit
1
isMatch is only true if the pattern matches the whole string.
add .* to match the first part of the filename
quote the dot as \.
no need for the $
this gives
(?i).*\.(pdf|docx?)
answered
Fabian Recktenwald
0
^.+\.((?:[pP][dD][fF]))$
^.+\.((?:[dD][oO][cC]))$
answered
Chris de Gelder
0
You could also use substring if you do not want to use Regex, find the last " . " and then use substring, you can evaluate it against a string or a list.