TXTechie Posted February 28, 2012 Share Posted February 28, 2012 I will have a folder full of files that look similar to this:RA_CUSTOMER_TRX_ALL_06o3415r7eobtvsr5965b7wrp0ha0200baq.xmlThe first part of the files ( words in ALL CAPS separated by underscore characters [ _ ] ) will be different for most every file as will the list of random-looking alpha-numeric characters that make up the second part of the files.I'm already looping through the folder of files parsing for some other things, but can someone help me with a way to parse out and capture the first part of the filename (RA_CUSTOMER_TRX_ALL_ in my example above - including the final underscore character) into a variable?I would very much appreciate the assistance!TX Techie Link to comment Share on other sites More sharing options...
GMK Posted February 28, 2012 Share Posted February 28, 2012 (edited) $sString = "RA_CUSTOMER_TRX_ALL_06o3415r7eobtvsr5965b7wrp0ha0200baq.xml" $sPrefix = StringRegExpReplace($sString, "(.*?)d.*xml", "1", 0) Edited February 28, 2012 by GMK Link to comment Share on other sites More sharing options...
TXTechie Posted February 28, 2012 Author Share Posted February 28, 2012 Thank you very much, GMK! That did the trick! Link to comment Share on other sites More sharing options...
UEZ Posted February 28, 2012 Share Posted February 28, 2012 (edited) Here my version: $sFile = "RA_CUSTOMER_TRX_ALL_06o3415r7eobtvsr5965b7wrp0ha0200baq.xml" $1st_part = StringRegExpReplace($sFile, "(?i)(w+_)(.*)", "$1") MsgBox(0, "Test", $1st_part) The first part can also have some digits. Br, UEZ Edited February 28, 2012 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Robjong Posted February 28, 2012 Share Posted February 28, 2012 I would do it in yet another way $sStr = "RA_CUSTOMER_TRX_ALL_06o3415r7eobtvsr5965b7wrp0ha0200baq.xml" $sPrefix = StringRegExpReplace($sStr, 'A([^d]+).*', "$1") @UEZ you don't need case insensitive matching (?i), w = [a-zA-Z0-9_] Link to comment Share on other sites More sharing options...
Malkey Posted February 28, 2012 Share Posted February 28, 2012 And the other view is "keep everything you don't catch" or "throw out everything you catch (match)". $sFile = "RA_CUSTOMER_TRX_ALL_06o3415r7eobtvsr5965b7wrp0ha0200baq.xml" $1st_part = StringRegExpReplace($sFile, "d.*xml", "") MsgBox(0, "Test", $1st_part) Link to comment Share on other sites More sharing options...
MilesAhead Posted February 29, 2012 Share Posted February 29, 2012 If we can assume the rule is the last _ is always followed by 0-9 then we can dispense with the regex $str = "RA_CUSTOMER_TRX_ALL_06o3415r7eobtvsr5965b7wrp0ha0200baq.xml" $count = StringInStr($str,"_",1,-1) If $count Then MsgBox(0x1040,"Test", StringLeft($str,$count)) Else MsgBox(0x1010,"Test", "_" & " Not found in string!") EndIf My Freeware Page Link to comment Share on other sites More sharing options...
UEZ Posted February 29, 2012 Share Posted February 29, 2012 I would do it in yet another way $sStr = "RA_CUSTOMER_TRX_ALL_06o3415r7eobtvsr5965b7wrp0ha0200baq.xml" $sPrefix = StringRegExpReplace($sStr, 'A([^d]+).*', "$1") @UEZ you don't need case insensitive matching (?i), w = [a-zA-Z0-9_] Yes you are right! I forgot to remove (?i) because my previous expression was different and I needed (?i). Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Robjong Posted February 29, 2012 Share Posted February 29, 2012 I suspected as much, it's usually copy/paste related Link to comment Share on other sites More sharing options...
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