youtuber Posted October 9, 2017 Share Posted October 9, 2017 I made a few attempts, but it fails when there are too many lines href = "and url between # My regular expression test <a\shref=[\"](.*?)#post or (?i)<a\s*href=[\"].*?([^\#]+)# Html code sample </a> <a href="https://example.com/asdf#post70403235"><img class=" Link to comment Share on other sites More sharing options...
kylomas Posted October 9, 2017 Share Posted October 9, 2017 youtuber, Try this... #include <ie.au3> #include <array.au3> Local $sAI = BinaryToString(InetRead('http://www.autoitscript.com')) Local $aARRAY = StringRegExp($sAI, '(?i).*href="([^"]+)"', 3) _ArrayDisplay($aARRAY) kylomas youtuber 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
mikell Posted October 9, 2017 Share Posted October 9, 2017 (edited) youtuber Try this pattern 'href="([^#"]+)' means : "find href=" , and then grab one or more chars wich are not a quote or hash" Edited October 9, 2017 by mikell youtuber 1 Link to comment Share on other sites More sharing options...
youtuber Posted October 9, 2017 Author Share Posted October 9, 2017 (edited) If Mikel is like that <a href="https://example.com/abcde" >abcde</a> <a href="https://example.com/asdf#post70403235"><img class=" And this is what I need https://example.com/asdf 'href="[^#](.*)#' Edited October 9, 2017 by youtuber Link to comment Share on other sites More sharing options...
mikell Posted October 9, 2017 Share Posted October 9, 2017 Just use my previous expression and add that the # is mandatory #Include <Array.au3> $s = '<a href="https://example.com/abcde" >abcde</a> <a href="https://example.com/asdf#post70403235"><img class=" ' $res = StringRegExp($s, 'href="([^#"]+)#' , 3) _ArrayDisplay($res) youtuber 1 Link to comment Share on other sites More sharing options...
iamtheky Posted October 9, 2017 Share Posted October 9, 2017 $s = '<a href="https://example.com/abcde" >abcde</a> <a href="https://example.com/asdf#post70403235"><img class=" ' msgbox(0, '' , stringreverse(stringsplit(stringreverse(stringsplit($s , "#" , 2)[0]) , '"' , 2)[0])) as expected from me youtuber 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
mikell Posted October 9, 2017 Share Posted October 9, 2017 23 minutes ago, iamtheky said: as expected from me How true .... so obvious iamtheky 1 Link to comment Share on other sites More sharing options...
youtuber Posted October 9, 2017 Author Share Posted October 9, 2017 @iamtheky This is the first time I see this method How do I get the return data with this method? How it is used? Sample $aGetConnect = stringreverse(stringsplit(stringreverse(stringsplit(WebConnect("https://www.autoitscript.com/forum/"), "#" , 2)[0]) , '"' , 2)[0]) ConsoleWrite("Receive data: " & $aGetConnect & @CRLF) Func WebConnect($address) Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET", $address, False) $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0") $oHTTP.SetRequestHeader("Accept", "*/*") $oHTTP.SetRequestHeader("Accept-Language", "tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3") $oHTTP.Send() If @error Then ConsoleWrite("Error connection") $oHTTP = 0 Return SetError(1) EndIf If $oHTTP.Status = 200 Then Local $sReceived = $oHTTP.ResponseText $oHTTP = Null Return $sReceived EndIf $oHTTP = Null Return -1 EndFunc Link to comment Share on other sites More sharing options...
iamtheky Posted October 9, 2017 Share Posted October 9, 2017 I just like manipulating strings without regexp for sport. I have no idea what nesting your function into that rats nest of string ops will yield. Regex is most certainly the solution you want to use, especially for maintenance purposes. youtuber 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) 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