gruntydatsun Posted November 6, 2017 Posted November 6, 2017 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.
Floops Posted November 6, 2017 Posted November 6, 2017 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.
mikell Posted November 6, 2017 Posted November 6, 2017 (edited) You might try these $filename = StringRegExpReplace($path, '.+\\(.+)', "$1") $withoutext = StringRegExpReplace($path, '^.*\\|\.[^.]*?$', "") $ext = StringRegExpReplace($path, '.+\.(.+?)', "$1") Edited November 6, 2017 by mikell
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now