Jump to content

Recommended Posts

Posted

OK, so first off I know I'm not very good at this.   I'm trying to make a pair of regular expressions.   One to grab the filename from a filepath and one to grab the extension from the filepath.  I know about _PathSplit but just thought I'd give this a try.

Example filepath that isn't working for me is:

C:\SharedData\CAT\v1.5.23\Back_2.7.2_Test.html

I'm using regular expression:

\\(\w+)\.\w{1,4}$

It's failing because there are full stops (periods) in the path and I'm a bit lost how to do it.  I tried ([\w|\.]+) which resulted in deafening silence.  Any help appreciated.

Posted
2 hours ago, gruntydatsun said:

I know I'm not very good at this

Don't worry you're not alone! I am also pretty bad at regular expressions but since I'm willing to learn more on the topic I gave it a try anyways.

#include <Array.au3>
#include <StringConstants.au3>

$sTest = "C:\SharedData\CAT\v1.5.23\Back_2.7.2_Test.html"
$sPattern = "(.*\\)(.*)\.(\w{1,4})$"

$aMatches = StringRegExp($sTest, $sPattern, $STR_REGEXPARRAYGLOBALMATCH)
_ArrayDisplay($aMatches)

There's probably a better way to do it but it seems to work for me.

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...