Extract file extension: Difference between revisions
Content added Content deleted
(→{{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: | Line 1: | ||
{{draft task}} |
{{draft task}} |
||
[[wp:Filename extension|Filename extensions]] are a rudimentary but commonly used way of identifying files types. |
|||
{{task heading}} |
{{task heading}} |
||
Line 5: | Line 7: | ||
Write a function or program that |
Write a function or program that |
||
* takes one string argument representing the path/URL to a file |
* takes one string argument representing the path/URL to a file |
||
* returns the |
* returns the filename extension according to the below specification, or an empty string if the 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. |
|||
⚫ | |||
For the purposes of this task, a filename extension |
|||
⚫ | |||
* 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}} |
{{task heading|Test cases}} |
||
Line 42: | Line 49: | ||
| <code>file.odd_one</code> |
| <code>file.odd_one</code> |
||
| <code></code> |
| <code></code> |
||
| ''empty string, |
| ''empty string, because <code>_</code> is not a letter or number'' |
||
|} |
|} |
||