Jump to content

Regular Expression Help, File Extension

Recommended Posts

I'm trying to write a regular expression to test if a file path has a file extension at the end.  I'm testing for...     after the last fullstop (period) then there's only characters up to the end of the string.   I get a bit fullstop happy writing regex and worry that im casting too wide a net.  This works i think but is there a better way?

Local $path = '"' & @ScriptDir & "\Log_" & @YEAR & "-" & @MON & "-" & @MDAY & ".csv" & '"'
$array = StringRegExp($path,"\.(.+)\z",0)
msgbox(1,"HAS FILE EXTENSION?",$array)

I know about PathSplit.  Just trying to learn.

Link to post
Share on other sites

You are grabbing the ending quotes.  Not sure you really want that.

This way will work with or without ending quotes :

$array = StringRegExp($path,'\.([^"]+)',1)


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...