borealis Posted May 2, 2012 Share Posted May 2, 2012 Hello,I'm fairly new to scripting, and I'm having a hard time with StringRegExp.$var = FileRead("C:\Users\Borealis\Desktop\test.txt")$ArrayURL = StringRegExp($var , '(?i)(?:\"\,\"authorizationURL\"\:\")(this part)(?:\"\})' , 3 )The test.txt file contains lines of this:...,"authorizationURL":"http:\/\/somewebsite\/blahblah\/authorize\/ANrIyF1zAg3n1Qn0rqaQ0wXFjaRSSSGSJ-Z3_A55K5zrkKJpwnU4_T_zT86fyjPcnh3cSrbrU6C_5ToaEA0Sq5DJR-2Yz40P-eCLhpaqNeom4Ym6Jm8mK9m6WLs7KXuZdlAPIPNsNhhS_IQQ6gdAsqldqW8hFimc6qYPNdUex_IlUpjI7mKjwrc"}Notice the extra \ whenever a / is in the URL. The extra \ is what I'm attempting to ignore. The StringRegExp seems to always return the string WITH the \ though. I've tried using methods with [^\\] but I think I may be structuring it incorrectly.What I need in the array is (the URL without the extra \ characters):http://somewebsite/blahblah/authorize/ANrIyF1zAg3n1Qn0rqaQ0wXFjaRSSSGSJ-Z3_A55K5zrkKJpwnU4_T_zT86fyjPcnh3cSrbrU6C_5ToaEA0Sq5DJR-2Yz40P-eCLhpaqNeom4Ym6Jm8mK9m6WLs7KXuZdlAPIPNsNhhS_IQQ6gdAsqldqW8hFimc6qYPNdUex_IlUpjI7mKjwrcThank you for any help!! Link to comment Share on other sites More sharing options...
czardas Posted May 2, 2012 Share Posted May 2, 2012 (edited) I'm wondering how the string was formatted in the first place. The easiest thing to do is remove unwanted characters with StringReplace, either before or, after you split the string by looping through the array. $var = "///hello///world///" $var = StringReplace($var, "", "") MsgBox(0, "", $var) Edited May 2, 2012 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
borealis Posted May 2, 2012 Author Share Posted May 2, 2012 (edited) Will StringReplace go through every element within an array, replace, then output into another Array? Or... Is there another way of accomplishing the above without StringReplace? (I don't know the size of the $ArrayURL as the files may have different quantities of URLs within) Edited May 2, 2012 by borealis Link to comment Share on other sites More sharing options...
iamtheky Posted May 2, 2012 Share Posted May 2, 2012 You can do it after your capture: *this is most certainly the long way around, eventhough seemingly effective #include <array.au3> Global $newstring $var = ',"authorizationURL":"http://somewebsite/blahblah/authorize/ANrIyF1zAg3n1Qn0rqaQ0wXFjaRSSSGSJ-Z3_A55K5zrkKJpwnU4_T_zT86fyjPcnh3cSrbrU6C_5ToaEA0Sq5DJR-2Yz40P-eCLhpaqNeom4Ym6Jm8mK9m6WLs7KXuZdlAPIPNsNhhS_IQQ6gdAsqldqW8hFimc6qYPNdUex_IlUpjI7mKjwrc"}' $ArrayURL = StringRegExp($var , '"authorizationURL":(.*)' , 3 ) $string = stringtrimright($ArrayURL[0] , 1) $split = stringsplit($string , "") for $i = 1 to $split[0] $newstring &= $split[$i] Next msgbox (0, '' , $newstring) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
czardas Posted May 2, 2012 Share Posted May 2, 2012 StringReplace is a string function and does not work on arrays. Once the data is in an array you need to loop through the array and alter each element separately. #include <Array.au3> ; For ArrayDisplay() Dim $aArray[5] = ["/1","/2","/3","/4","/5"] For $i = 0 To UBound($aArray) -1 $aArray[$i] = StringReplace($aArray[$i], "", "") Next _ArrayDisplay($aArray) operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
borealis Posted May 2, 2012 Author Share Posted May 2, 2012 StringReplace is a string function and does not work on arrays. Once the data is in an array you need to loop through the array and alter each element separately. #include <Array.au3> ; For ArrayDisplay() Dim $aArray[5] = ["/1","/2","/3","/4","/5"] For $i = 0 To UBound($aArray) -1 $aArray[$i] = StringReplace($aArray[$i], "", "") Next _ArrayDisplay($aArray) Thank you! I didn't see Ubound in the help file - I couldn't figure out how I would loop through an array with an unknown size. Very helpful - Thank you for your time. Link to comment Share on other sites More sharing options...
czardas Posted May 2, 2012 Share Posted May 2, 2012 (edited) No problem, but like boththose suggested there are likely more ways than one to accomplish this. I didn't look at the regexp because I'm not sure exactly how you want to spilt the string. If what you have is working then I'm happy to help. These are basic things to learn about. The differences between variable types. Edited May 2, 2012 by czardas operator64 ArrayWorkshop 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