in reply to using split on a string
This pattern will match at least one non-dot character, a dot, then capture one or more non . / and \ characters until the end of string.if ($pubupload =~ m![^.]\.([^./\\]+)$!) { $extension = $1; }
$pubupload = 'C:\Documents and Settings\Administrator\Desktop\china.tx +t'; DB<1> if ($pubupload =~ m![^.]\.([^./\\]+)$!) { $extension = $1; } DB<2> print "[$extension]" [txt]
Update:
Modified pattern so that it won't be fooled by dot files (filenames with leading dot) like .notanextension and will require at least one non-dot character in the filename, for example: a.txt.
|
|---|