tbaror Posted April 1, 2009 Share Posted April 1, 2009 Hello, i am trying to capture file name in a string might be for example "-configfile te56stds -r 8798" or "-configfile te56stds.conf -r 8798" i figure out pattern like example below but i cant get it works please advice Thanks $cliArray = '(?:-configfile) ([.*\..{4}] [.*$])' $cliArra = StringRegExp("-configfile te56stds. -r 8798",$cliArray ,2) Link to comment Share on other sites More sharing options...
tbaror Posted April 1, 2009 Author Share Posted April 1, 2009 Hello, i am trying to capture file name in a string might be for example "-configfile te56stds -r 8798" or "-configfile te56stds.conf -r 8798" i figure out pattern like example below but i cant get it works please advice Thanks $cliArray = '(?:-configfile) ([.*\..{4}] [.*$])' $cliArra = StringRegExp("-configfile te56stds. -r 8798",$cliArray ,2) Link to comment Share on other sites More sharing options...
Authenticity Posted April 1, 2009 Share Posted April 1, 2009 Metacharacters like . or * doesn't govern their true meaning within character class [...] so it's erroneous pattern or at least it doesn't match exactly what you want it to match. Example: #include <Array.au3> Dim $sRawText = "-configfile te56stds.conf -r 8798" Dim $sPattern = '-configfile\s*((?:"[^"]++"|[^ ]++)\s*-r\s*\d++)' Dim $aMatches = StringRegExp($sRawText, $sPattern, 1) If IsArray($aMatches) Then _ArrayDisplay($aMatches) $sRawText = "-configfile C:\Configuration\te56stds.conf -r 8798" $aMatches = StringRegExp($sRawText, $sPattern, 1) If IsArray($aMatches) Then _ArrayDisplay($aMatches) $sRawText = '-configfile "C:\Con fi gu rat ion\te56stds.conf" -r 8798' $aMatches = StringRegExp($sRawText, $sPattern, 1) If IsArray($aMatches) Then _ArrayDisplay($aMatches) $sRawText = '-configfil "C:\Con fi gu rat ion\te56stds.conf -r 8798' $aMatches = StringRegExp($sRawText, $sPattern, 1) If IsArray($aMatches) Then _ArrayDisplay($aMatches) ; No match If you want to partition the elements to - "-configfile"(don't capture), "file"(capture), "-r"(don't capture), "number"(capture), use just parentheses where you want to capture and leave the rest outside of it. Also, 2 is the whole match, even what you don't want to capture. Link to comment Share on other sites More sharing options...
Xenobiologist Posted April 1, 2009 Share Posted April 1, 2009 Hi, isn't it this what you want? #include <Array.au3> Dim $sRawText[3] = ['-configfile te56stds.conf -r 8798"', '-configfile "c:\Daten und Einstellungen\te56stds.conf" -r 8798"', '"-configfile te56stds -r 8798"'] Dim $sPattern = '-configfile\s*"*(.*?)(?="|-)' For $i = 0 To UBound($sRawText) - 1 Dim $aMatches = StringRegExp($sRawText[$i], $sPattern, 3) If IsArray($aMatches) Then _ArrayDisplay($aMatches) Next Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
mary Posted April 1, 2009 Share Posted April 1, 2009 2 solutions: 1- simple one: juste use $Array=stringsplit("your string here", " ",1) 2-with Regexp: $s="-configfile te56stds -r 8798" $Array=StringRegExp($s, "(\w+)",3) Link to comment Share on other sites More sharing options...
Xenobiologist Posted April 1, 2009 Share Posted April 1, 2009 Hi, second time? #include <Array.au3> Dim $sRawText[3] = ['-configfile te56stds.conf -r 8798"', '-configfile "c:\Daten und Einstellungen\te56stds.conf" -r 8798"', '"-configfile te56stds -r 8798"'] Dim $sPattern = '-configfile\s*"*(.*?)(?="|-)' For $i = 0 To UBound($sRawText) - 1 Dim $aMatches = StringRegExp($sRawText[$i], $sPattern, 3) If IsArray($aMatches) Then _ArrayDisplay($aMatches) Next Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
tbaror Posted April 1, 2009 Author Share Posted April 1, 2009 (edited) Thanks All Edited April 1, 2009 by tbaror 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