[Question]
  [
Your challenge is to find the file extension of a provided filename:
```
hi.txt -> txt or .txt
carrot.meme -> meme or .meme
lol (undefined behavior)
what..is..this..file -> file or .file
.bashrc -> bashrc or .bashrc
[[email protected]](/cdn-cgi/l/email-protection)[]h -> h0wC[]h or .h0wC[]h
agent.000 -> 000 or .000
```
**You must get the text from the last `.` or after the last `.` to the end of the string.** The first capturing group match of the regular expression `/\.([^.]+)$/` works, and so does splitting the input on `.`s and returning the last one.
The file name will always contain at least one `.`, but it may contain multiple `.`. (see examples)
The input will always match [`^[.a-zA-Z0-9^!\[\]{}@$%+=]+$`](https://regex101.com/r/KW4sF3/2).
  
[Answer]
# [Retina](https://github.com/m-ender/retina), 5 bytes
```
.*\.
```
Replaces everything and a dot with nothing at all.
[Try it online!](https://tio.run/nexus/retina#@6@nFaPH9f9/RmpOTr5eeX5RTopeSWpxiV5WQbpeakUqAA "Retina – TIO Nexus")
[Answer]
## JavaScript (ES6), 19 bytes
Returns the full filename when there's no file extension. I suppose this is an acceptable *undefined behavior*.
```
let f =
s=>s.split`.`.pop()
console.log(f("hi.txt"))               // -> txt
console.log(f("carrot.meme"))          // -> meme
console.log(f("lol"))                  // -> undefined behavior
console.log(f("what..is..this..file")) // -> file
console.log(f("[[email protected]](/cdn-cgi/l/email-protection)[]h")) // -> h0wC[]h
console.log(f(".bashrc")) // -> bashrc
```
[Answer]
## Mathematica, 13 22 bytes
*Edit: Not sure how I missed the `".bashrc"` test case. Thanks to Artyer for keeping me honest.*
```
FileExtension["a"<>#]&
```
If the input matches `\.[^.]+`, then `FileExtension` just returns the empty string, so we prepend the letter `a`. In any other case, prepending `a` doesn't affect output of `FileExtension`.
[Answer]
# POSIX Shell, 13
```
echo ${1##*.}
```
[Try it online](https://tio.run/nexus/bash#NYzNCsIwEITvPsWwrRchC54F3yW0GxJIs5IsKEifPY1C5/DB/DBBK0yaLb4JUgHFxPYxAi2@VjXeZJPhsubBd/TGnBqzxR9DykIPrHrB0KumYgF0bXBPEObv@bz/@yYG5zCfaZcl6ljdp@nGe1@1SD8A).
[Answer]
# c function, 21
* 1 byte saved thanks to @Dennis.
* 3 bytes saved thanks to @JohanduToit.
* 2 bytes saved thanks to @Neil.
* 1 byte saved thanks to @algmyr.
```
f(s){s=rindex(s,46);}
```
[Try it online](https://tio.run/nexus/c-gcc#XZDBboMwDIbvPIUVqVJCWehh2oV1L9JxiLKkWIJQxWarVvHsLMA00HxIfv2Of33O5CWpB50jhg93l1Q8v6hqnDAwdAYDyFmZeLUF2D4Qg21MhDw5nwoeGaRaHXbE1pCjSw3n385cokHNdxbF5lgTY8@6c53b2WUp2r4VRVI5WDOkKDBA7urN0DLk5Rbw1RjWGklrbubTY@vE0h6r5ZqhscoW7fuYtkhMpwoQXkESfrveyz9gBSX89y6nWqn0/nhUu11u6ZfYS3EgeHqDA72HhLvNYF3APgPnjBVrRYmOhxgSSDZOPw).
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 3 bytes
2 bytes of code, +1 for the `h` flag.
```
q.
```
### Explanation:
```
q.       Split the input by `.`
   -h    Return the last item
```
[Try it online!](https://tio.run/nexus/japt#@1@o9/@/UnlGYomeXmaxnl5JBohMy8xJVdLNAAA "Japt – TIO Nexus")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes
```
'.¡¤
```
[Try it online!](https://tio.run/nexus/05ab1e#@6@ud2jhoSX//5dnJJbo6WUW6@mVZIDItMycVAA "05AB1E – TIO Nexus") or [Try All Tests](https://tio.run/nexus/05ab1e#qymr/K@ud2jhoSX/K5UO77dSULLX@Z@RqVdSUcKVnFhUlF@il5uam8qVk5/DVZ6RWKKnl1msp1eSASLTMnNSufSSEoszipK5QgwMfB3yjL0TA6L0MgzKnaNjMwA "05AB1E – TIO Nexus")
```
'.   # Push '.'
  ¡  # Split on occurrences of '.'
   ¤ # Tail
```
[Answer]
# [Neo4j Cypher](http://neo4j.com/docs/developer-manual/current/cypher), 24 bytes
```
return split($i,".")[-1]
```
Input is in a param (`i`), probably the only way for cypher to take input. Pretty straightforward. [Cypher has never been used on PPCG before](https://codegolf.stackexchange.com/search?q=Cypher)
[Answer]
# PHP, 21 Bytes
```
<?=pathinfo($argn,4);
```
[Try it online!](https://tio.run/nexus/php#s7EvyCjgUkksSs@zVcrI1CupKFGy5rK3@29jb1uQWJKRmZeWrwGW1jHRtP7/HwA "PHP – TIO Nexus")
is a shorter expression for
```
<?=pathinfo($argn)[extension];
```
[pathinfo](http://php.net/manual/en/function.pathinfo.php)
# PHP, 27 Bytes
```
<?=end(explode(".",$argn));
```
[explode](http://php.net/manual/en/function.explode.php)
[Try it online!](https://tio.run/nexus/php#s7EvyCjgUkksSs@zVcrI1CupKFGy5rK3@29jb5ual6KRWlGQk5@SqqGkp6QDVqWpaf3/PwA "PHP – TIO Nexus")
## PHP <7.0, 26 Bytes
```
<?=end(split("\.",$argn));
```
deprecated [split](http://php.net/manual/en/function.split.php)
[Answer]
# [Taxi](https://bigzaphod.github.io/Taxi/), 1397 bytes
```
Go to Post Office:w 1 l 1 r 1 l.Pickup a passenger going to Chop Suey.Go to Chop Suey:n 1 r 1 l 4 r 1 l.[a]Pickup a passenger going to Narrow Path Park.Go to Narrow Path Park:n 1 l 1 r 1 l.Go to Chop Suey:e 1 r 1 l 1 r.Switch to plan "b" if no one is waiting.Switch to plan "a".[b]Go to The Babelfishery:n 1 l 1 l.[c]Go to Fueler Up:n.Go to Joyless Park:n 2 r.Go to Narrow Path Park:w 1 r 3 l.Pickup a passenger going to Cyclone.Go to Cyclone:w 1 l 1 r 2 l.Pickup a passenger going to Crime Lab.Pickup a passenger going to Joyless Park.'.' is waiting at Writer's Depot.Go to Writer's Depot:s.Pickup a passenger going to Crime Lab.Go to Crime Lab:n 1 r 2 r 2 l.Switch to plan "c" if no one is waiting.Go to Narrow Path Park:n 5 l.[d]Pickup a passenger going to Chop Suey.Go to Chop Suey:e 1 r 1 l 1 r.Go to Narrow Path Park:n 1 l 1 r 1 l.Switch to plan "e" if no one is waiting.Switch to plan "d".[e]Go to Joyless Park:e 1 r 3 l.Switch to plan "f" if no one is waiting.Pickup a passenger going to Narrow Path Park.Go to Fueler Up:w 1 l.Go to Narrow Path Park:n 4 l.Switch to plan "e".[f]Go to Narrow Path Park:w 1 r 3 l.[g]Switch to plan "h" if no one is waiting.Pickup a passenger going to KonKat's.Go to KonKat's:e 1 r.Pickup a passenger going to KonKat's.Go to Narrow Path Park:n 2 l.Switch to plan "g".[h]Go to KonKat's:e 1 r.Pickup a passenger going to Post Office.Go to Post Office:s 3 r 1 l.
```
[Try it online!](https://tio.run/##nVTLboMwEPyVVS65WWqaXji2VSs1VRsprXpAHAxZsBVqI9sR5eupCYYQAnkdbGutfczsjm3oHy/LVwlGwlJqA59xzCP0criD1C5VnWTJo802AwoZ1RpFggoSyUVSRT0xmcFqiwWps7S2J5p4mLs8Pg1OpfqgSskcltQwu6mNy9i/3iXeg@uXxbasPckq5yZilUeWUgGTcAI8BiFBCgSuIafc2PJHfnRC/DCoc38xhEcaYhpzzVAVLQDLKHI@L1tMLZfvzBMO0ZssUtS6gTyzYEb45DvE9@caXUSpBd3wra3OoGbn4hX/RXin4UmvLmoyJdNOj4Aa@FHcoJpqeMZMGofl8NLTF8JwRBrb6WXmqPQHEo0MblQjD9V41sFt2j0U0UU67APGC5W2tkrDYEAz2MqiHxKPpL7hce11m3de0wDV@SBF4sfBWVX7SdCPZDcwWEixoGaqHcbGrPt0TeQAuyHFJZYdC64u1vlGyfHHqm1Har2UZc6oIYRrQgyr9pin@A8 "Taxi – Try It Online")
Taxi doesn't have a reverse function so this ballooned pretty quickly. The logic is:
1. Break the string into characters
2. Reverse the array
3. Iterate through each until a period is found, storing each in a FIFO array
4. Empty the array (because there's only one LIFO array available)
5. Dump the FIFO array into the LIFO array
6. Concatenate the LIFO array and output
[Answer]
# [GNU Make](https://www.gnu.org/software/make/), 12 bytes
```
$(suffix $1)
```
Not using a builtin, 27 bytes:
```
$(lastword $(subst ., ,$1))
```
[Answer]
## Batch, 10 bytes
```
@echo %~x1
```
Strangely competitive for once.
[Answer]
# [V](https://github.com/DJMcMayhem/V), ~~5~~, 3 bytes
Since more of this answer is unprintable than printable, here is a hexdump:
```
00000000: cd81 ae                                  ...
```
[Try it online!](https://tio.run/nexus/v#@3@491DjoXX//2dk6pVUlHAlJxYV5Zfo5abmpnLl5OdwlWcklujpZRbr6ZVkgMi0zJxUAA "V – TIO Nexus")
This uses [Jan Dvorak's algorithm](https://codegolf.stackexchange.com/a/120937/31716), it just happens to be a more efficient encoding of it.
Explanation:
```
Í       " Remove all occurrences of:
 0x81   "   Anything (greedy)
     ®  "   Followed by a dot 
```
Old solution:
```
$T.d|
```
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 22 bytes
```
s=>s.Split('.').Last()
```
Implicit `using System.Linq;` FTW!
[Try it online!](https://tio.run/##NctNawIxEIDhc/MrggibgB0CvflFQVoorlBUKLR6mMasGdidlWR0BfG3bymll/c5vT4/@kz965n9NEsiPo70n3Nd6Znu82yeYXOqSUwBhYUSsxjbT1TVpoA@anPBpEkT6zeGdcDDtn3hg7H/044La9XDRyIJJXEww8GN7uOd3CpD9j6wkz4SyFWUx5RagSY0QXURBYAygMTfVlQHBd@YY/Jq69zqmZ@W@P4J0XWLr31UeAws4Jz7AQ "C# (Visual C# Interactive Compiler) – Try It Online")
[Answer]
# Vim, 5 bytes
```
$F.d0
```
Explanation: find last `.` in line, delete everything before it
Another, longer, but in my opinion still interesting approach with 9 bytes (notice the trailing new line)
```
d/.*\./e
```
This one works similarly, 5 bytes (again, trailing new line):
```
d?\.
```
[Answer]
# PowerShell, ~~34~~ 26 bytes
-8 bytes thanks to @mazzy
```
(Read-Host).Split('.')[-1]
```
Takes input from STDIN. Actually managed to golf it down shorter than the built-in.
# PowerShell, 20 bytes
```
($args-split'.')[-1]
```
Takes input from commandline arguments. Big thanks to @mazzy again!
# PowerShell (with built-in), 36 bytes
```
[IO.Path]::GetExtension((Read-Host))
```
[Answer]
# [Forth (gforth)](http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/), 45 bytes
```
: f begin 1 -1 d+ s" ."search 0= until type ;
```
[Try it online!](https://tio.run/##NYzBCsIwEETvfsWQq3RJ9WZRBI8iePCkeIht2gTStCRbql9fU6yX2Xm7s1N3gU3W1POYph1qvHRjPXJkOao1ogCJqFUoDeQeg2frwJ9eo0jpHptq6H9MAsgOEKmiDChW6dNY4jcL9DOUKoSOqdWtXjauc4sbjWIiG4nYzFpb9w/RS0UTyoVuUl6OfntW1zsZOZ4eT7NcVKM9k5Qy8fQF "Forth (gforth) – Try It Online")
### Code Explanation
```
: f              \ start a new word definition
  begin          \ start an indefinite loop
    1 -1 d+      \ remove the first character from the string
    s" ."search  \ find the length and starting address of the first substring that starts with '.'
    0=           \ check if '.' was found in the string
  until          \ end the loop if not
  type           \ output the result
;                \ end the word definition
 
```
[Answer]
# Python 3, 29 bytes
```
print(input().split(".")[-1])
```
[Answer]
# [Rust](https://www.rust-lang.org/), 34 bytes
```
|p|p.extension().or(p.file_stem())
```
Usable as a `fn(&std::path::Path) -> Option<&std::ffi::OsStr>`.
[Try it online!](https://tio.run/##jY5NCsIwEIX3PUXsQiagOcD4s3NdwQOUVic0YJOYmWJFPXstulB04@Yx8L75eKljGaxXbeU8aHXNjiTKovUwZTkgxkoaxO2Yer4uorjgl6/GWodY8E7SWq2GW7xFQ72Q5xEBbUKCaKw7UslCLWg9LLKOST1/AyN23vWflk0vi6xipiQlnSZgfxYgejpD3jgjveRaz9QutARfa8Y7hbasL0IMdf5C9X9qU1fcpP2/7jc@@u/DAw "Rust – Try It Online")
[Answer]
# [sed](https://www.gnu.org/software/sed/), 8 bytes
```
s:.*\.::
```
[Try it online!](https://tio.run/nexus/sed#@19spacVo2dl9f9/RqZeSUUJV3JiUVF@iV5uam4qV05@Dld5RmKJnl5msZ5eSQaITMvMSQUA "sed – TIO Nexus")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
ṣ”.Ṫ
```
A monadic link taking the file name and returning the extension with no leading `.`.
**[Try it online!](https://tio.run/nexus/jelly#@/9w5@JHDXP1Hu5c9f////KMxBI9vcxiPb2SDBCZlpmTCgA "Jelly – TIO Nexus")**
### How?
Literally does what was asked...
```
ṣ”.Ṫ - Main link: list of characters, f
 ”.  - literal '.'
ṣ    - split f at occurrences of '.'
   Ṫ - tail (get the last chunk)
```
[Answer]
# [Go](https://golang.org/), 85 bytes
Go is... troublesome.
```
import(."fmt"
."os"
."strings")
func main(){s:=Split(Args[1],".");Print(s[len(s)-1])}
```
[Try it online!](https://tio.run/nexus/go#K0hMzk5MT1XITczM@5@ZW5BfVKKhp5SWW6LEpaeUXwwii0uKMvPSi5U0udJK85LBKjU0q4utbIMLcjJLNByL0oujDWN1lPSUNK0DgEpLNIqjc1LzNIo1dQ1jNWv///@fkalXUlECAA "Go – TIO Nexus")
A sample of parentheses from the code:
```
()(){([])([()])}
```
[Answer]
# JavaScript (ES6), ~~33~~ ~~31~~ 28 bytes
```
s=>s.slice(s.lastIndexOf`.`)
```
Spec change in comments removes the need for `+1`.
-3 bytes thanks to nderscore
[Answer]
# Common Lisp, 57 bytes
```
(lambda(s)(#1=reverse(subseq #2=(#1# s)0(search"."#2#))))
```
[Try it online](https://tio.run/nexus/clisp#DcixDkBADADQX5Hr0i4NdqNgQQ6D8dCEBOEafv944wt4@e2cEXd3TItDJYQk8/KKV0F9JpU7gjT7FyKlGFWcn1fDBlKgn2mHnnlsBsvc9baqC@Yyt7khCuED) (added some bytes to call this anonymous function and display returned string)
### Explanation
```
(#1=reverse ...)     ;reverse is now accessible with #1# - saves 1 byte. I 
                     ;also need to reverse output of function inside to 
                     ;get extension in correct order
#2=(#1# s)           ;reverse of input string is now accessible with #2#
(search"."#2#)       ;I take reversed string and search for "." to get position of 
                     ;first instance of "." in string from the end of it
(subseq ... 0 ...)   ;get part of reversed string, 
                     ;starting from first character and ending just 
                     ;before first occurance of "."
                     ;this gives reversed extension
```
I get substring of reversed string, starting from 0, ending on this
[Answer]
# Gema, 3 characters
```
*.=
```
Sample run:
```
bash-4.4$ gema '*.=' <<< 'what..is..this..file'
file
```
[Answer]
# Javascript (ES5), 38 bytes
```
function(s){return s.split(".").pop()}
```
[Answer]
# C#, ~~33~~ 41 bytes
```
a=>a.Split('.').Last();
```
Edit as suggested:
```
using System.Linq;a=>a.Split('.').Last();
```
[Answer]
# Awk, ~~14~~ 13 characters
(~~10~~ 9 characters code + 4 characters command line option.)
```
{$0=$NF}1
```
Thanks to:
* [Robert Benson](https://codegolf.stackexchange.com/users/45724/robert-benson) for spotting the unnecessary semicolon (-1 character)
Sample run:
```
bash-4.4$ awk -F. '{$0=$NF}1' <<< $'hi.txt\ncarrot.meme\nlol\nwhat..is..this..file\n.bashrc\[[email protected]](/cdn-cgi/l/email-protection)[]h'
txt
meme
lol
file
bashrc
h0wC[]h
```
[Answer]
# [Lua](https://www.lua.org), ~~53~~ 30 bytes
Replaces everything upto the last `.` with the empty string `''`.
Double parenthesis to select only the first return value of `gsub`.
Any golfing tips are welcome, I'm rusty in lua...
```
print(((...):gsub('.*%.','')))
```
[Try it online!](https://tio.run/nexus/lua#@19QlJlXoqGhoaenp2mVXlyapKGup6Wqp66jrq6pqfn///@kxDwg1EtMSkxOLEnVS61IBQA "Lua – TIO Nexus")
[Answer]
# JS (ES6), ~~26~~ 25 bytes
```
x=>/\.([^.]+)$/.exec(x)[1]
```
-1 byte thanks to Shaggy
```
document.querySelector('pre').innerText = (x=>/\.([^.]+)$/.exec(x)[1])("example.txt")
```
```
<input oninput = "document.querySelector('pre').innerText = (x=>x.match(/\.([^.]+)$/)[1])(this.value)" value = "example.txt">
<pre></pre>
```
Alternate, 29 bytes:
```
x=>(y=x.split`.`)[y.length-1]
```
]