Extract file extension: Difference between revisions

Content added Content deleted
(→‎{{header|J}}: non-regex implementation)
Line 171:
=={{header|J}}==
 
'''Implementation:'''
 
<lang J>require'regex'
Line 182:
The left verb uses rxmatch to find the beginning position of the match and its length. The right verb is the identity function. The middle verb extracts the desired characters from the original argument. (For a non-match, the length of the "match" is zero so the empty string is extracted.)
 
 
Task examples:
'''Alternative non-regex Implementation'''
<lang J>ext=: #~ [: +./\ e.&'.' *. [: -. [: +./\. -.@e.&(AlphaNum_j_,'.')</lang>
 
'''Task examples:'''
 
<lang J> ext 'picture.jpg'