supersonic Posted January 30, 2009 Share Posted January 30, 2009 Hi, I have e. g. the following file name: windowsmedia11-kb936782-x86-deu_315dad75eb6cbc69a4ddaf80cd309ab3a6effdf2.exe ... and I would like to extract the part between "windowsmedia11-kb936782-x86-deu_" and ".exe". The result is "315dad75eb6cbc69a4ddaf80cd309ab3a6effdf2" (= SHA1). I use the following code to extract: $xSHA1 = _StringBetween(_xFileName($xArrLst[$k]), "_", ".", -1, -1) ... getting an array ($xSHA1[0]). Is there a way to extract the string with StringRegExp()? I don't like to return into an array. I just need the plain string. Working with _ArrayToString() isn't really a choice. I would like to realize this in one single code line. Has anyone an idea? Greets, -supersonic. Link to comment Share on other sites More sharing options...
picaxe Posted January 30, 2009 Share Posted January 30, 2009 (edited) $t = "windowsmedia11-kb936782-x86-deu_315dad75eb6cbc69a4ddaf80cd309ab3a6effdf2.exe" ConsoleWrite(StringTrimLeft(StringTrimRight($t, StringLen($t) - StringInStr($t, ".") + 1), StringInStr($t, "_")) & @LF)oÝ÷ Ø@ÈN)²z-èÆkÊØb±«¢+Ù ½¹Í½±]ɥѡMÑÉ¥¹IáÁIÁ± ÀÌØíаÅÕ½Ðì ý¤¤ ¸¬¥| ÀäÈí¸¬¤ ÀäÈì¸ÀäÈíܬ¤ÅÕ½Ðì°ÅÕ½ÐìÀÌØìÈÅÕ½Ð줵Àí1 Edited January 30, 2009 by picaxe Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 30, 2009 Moderators Share Posted January 30, 2009 Hi, I have e. g. the following file name: windowsmedia11-kb936782-x86-deu_315dad75eb6cbc69a4ddaf80cd309ab3a6effdf2.exe ... and I would like to extract the part between "windowsmedia11-kb936782-x86-deu_" and ".exe". The result is "315dad75eb6cbc69a4ddaf80cd309ab3a6effdf2" (= SHA1). I use the following code to extract: $xSHA1 = _StringBetween(_xFileName($xArrLst[$k]), "_", ".", -1, -1) ... getting an array ($xSHA1[0]). Is there a way to extract the string with StringRegExp()? I don't like to return into an array. I just need the plain string. Working with _ArrayToString() isn't really a choice. I would like to realize this in one single code line. Has anyone an idea? Greets, -supersonic._StringBetween() uses RegEx by default, so you would have to escape the decimal with a slash. The values are in the elements of the array, you should learn how to work with them because RegEx is only going to return an array unless you use RegExReplace Array way:Local $s_str = "windowsmedia11-kb936782-x86-deu_315dad75eb6cbc69a4ddaf80cd309ab3a6effdf2.exe" Local $a_sre = StringRegExp($s_str, ".*?deu_(.*?)\.", 1) If Not @error Then MsgBox(64, "Info", $a_sre[0]) Non-Array way:Local $s_str = "windowsmedia11-kb936782-x86-deu_315dad75eb6cbc69a4ddaf80cd309ab3a6effdf2.exe" Local $s_sre = StringRegExpReplace($s_str, "(.*?deu_)(.*?)(\..*?\z)", "$2") If @extended Then MsgBox(64, "Info", $s_sre) Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
BrettF Posted January 30, 2009 Share Posted January 30, 2009 But I thought the helpfile said it used string manipulation by default?$iSRE Optional: Toggle for regular string manipulation or StringRegExp search. Default is regular string manipulation.But feel free to correct me if I'm wrong Cheers,Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
supersonic Posted January 30, 2009 Author Share Posted January 30, 2009 Thank you, works also pretty well! _StringBetween() uses RegEx by default, so you would have to escape the decimal with a slash. The values are in the elements of the array, you should learn how to work with them because RegEx is only going to return an array unless you use RegExReplace Array way:Local $s_str = "windowsmedia11-kb936782-x86-deu_315dad75eb6cbc69a4ddaf80cd309ab3a6effdf2.exe" Local $a_sre = StringRegExp($s_str, ".*?deu_(.*?)\.", 1) If Not @error Then MsgBox(64, "Info", $a_sre[0]) Non-Array way:Local $s_str = "windowsmedia11-kb936782-x86-deu_315dad75eb6cbc69a4ddaf80cd309ab3a6effdf2.exe" Local $s_sre = StringRegExpReplace($s_str, "(.*?deu_)(.*?)(\..*?\z)", "$2") If @extended Then MsgBox(64, "Info", $s_sre) Link to comment Share on other sites More sharing options...
supersonic Posted January 30, 2009 Author Share Posted January 30, 2009 Thanks, perfect! I'm trying to understand: Why do you use "\d" instead of "\w"? And why do you use "\w+" instead of "\w.+"? As fas as I understood "\d" defines the characters of the string to extract. Right? "\d" means "Match any digit (0-9)." But the extracted string also contains "a-z" or "A-Z" (lowercase/uppercase possible). The input string consists of only one single line. In case of two or more lines, I would like to cut with "\w.+". Right? Greets, -supersonic. $t = "windowsmedia11-kb936782-x86-deu_315dad75eb6cbc69a4ddaf80cd309ab3a6effdf2.exe" ConsoleWrite(StringTrimLeft(StringTrimRight($t, StringLen($t) - StringInStr($t, ".") + 1), StringInStr($t, "_")) & @LF)oÝ÷ Ø@ÈN)²z-èÆkÊØb±«¢+Ù ½¹Í½±]ɥѡMÑÉ¥¹IáÁIÁ± ÀÌØíаÅÕ½Ðì ý¤¤ ¸¬¥| ÀäÈí¸¬¤ ÀäÈì¸ÀäÈíܬ¤ÅÕ½Ðì°ÅÕ½ÐìÀÌØìÈÅÕ½Ð줵Àí1 Link to comment Share on other sites More sharing options...
GameIDevelp Posted January 30, 2009 Share Posted January 30, 2009 how I change the ".exe" in "windowsmedia11-kb936782-x86-deu_315dad75eb6cbc69a4ddaf80cd309ab3a6effdf2.exe" with " ,, ===> 0cd309ab3a6effdf2"exe" to stop read at "exe in my code I wont to use fffsfsf_program"numerico and I wont to read next at line _program" ????? .. ? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 30, 2009 Moderators Share Posted January 30, 2009 @sonicTake a look at some regex tutorials to understand what escape characters and such are.The regex engine AutoIt uses is called PCRE (Perl Compatible Regular Expressions).how I change the ".exe" in "windowsmedia11-kb936782-x86-deu_315dad75eb6cbc69a4ddaf80cd309ab3a6effdf2.exe" with " ,, ===> 0cd309ab3a6effdf2"exe" to stop read at "exe in my code I wont to use fffsfsf_program"numerico and I wont to read next at line _program" ????? ..?And that makes sense to you at all? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
picaxe Posted January 30, 2009 Share Posted January 30, 2009 Why do you use "\d" instead of "\w"?Mistake on my part, which fortunately didn't change the result. SmOke_N's regexp will be better.In case of two or more linesTry$t = "windowsmedia11-kb936782-x86-deu_315dad75eb6cbc69a4ddaf80cd309ab3a6effdf2.exe" & @LF _ & "windowsmedia11-kb936782-x86-deu_315dad75eb6cbc69akvjdsaf80cd309ab3a6effd.exe" & @CRLF _ & "windowsmedia11-kb936782-x86-deu_315dad75ertrbc69akvjdsaf80cd309ab3a6effd.exe" & @LF _ & "windowsmedia11-kb936782-x86-deu_315dad75eb6cbc69akvjdsaf80tyt09ab3a6effd.exe" & @CRLF _ & "windowsmedia11-kb935582-x86-deu_315dad75eb6cbc69akvjdsaf8077t09ab3a6effd.exe" ConsoleWrite(StringRegExpReplace($t, "(?i)(.+)_(\w+)\.(\w+)", "$2") & @LF) Link to comment Share on other sites More sharing options...
picaxe Posted January 30, 2009 Share Posted January 30, 2009 @supersonic Search examples forum for regexp tester. 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