vendredi 3 avril 2015

How to use regex to get file exxtentions?

I'm trying extract a substring from a string that contains a filename or directory. The substring being extracted should be the file extension. I've done some searching online and discovered I can use regular expressions to accomplish this. I've found that "^.[\w]+$" is a pattern that will work to find file extensions. The problem is that I'm not fully familiar with regular expressions and its functions.


Basically If i have a string like "C:\Desktop\myFile.txt" I want the regualar expression to then find and create a new string containing only ".txt".


Aucun commentaire:

Enregistrer un commentaire