Extract file extension: Difference between revisions

→‎Task: some more re-wording, and explicitly restrict to ASCII letters and numbers
(→‎{{header|Perl 6}}: replace the solution with a simpler one, and mention the built-in ".extension" method)
(→‎Task: some more re-wording, and explicitly restrict to ASCII letters and numbers)
Line 1:
{{draft task}}
 
[[wp:Filename extension|Filename extensions]] are a rudimentary but commonly used way of identifying files types.
 
{{task heading}}
Line 5 ⟶ 7:
Write a function or program that
* takes one string argument representing the path/URL to a file
* returns the file'sfilename extension according to the below specification, or an empty string if itthe filename has no extension.
 
 
If your programming language (or standard library) has built-in functionality for extracting a filename extension, show how it would be used, and clearly state how its behavior differs from this specification.
 
{{task heading|DetailsSpecification}}
 
For the purposes of this task, a filename extension
{{task heading|Details}}
 
* occurs at the very end of the filename
* An extension appears after the last period in the file's name, and consists of one or more letters or numbers.
* consists of a period, followed by one or more ASCII letters or numbers
* The file name is separated from preceding directory parts, if any, by a forward slash.
 
{{task heading|Test cases}}
Line 42 ⟶ 49:
| <code>file.odd_one</code>
| <code></code>
| ''empty string, asbecause an<code>_</code> extensionis (bynot thisa definition),letter cannotor contain an underscorenumber''
|}
 
Anonymous user