Jump to content

A question about regex?


Recommended Posts

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

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

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

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 by youtuber
Link to comment
Share on other sites

$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 :)

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

@iamtheky This is the first time I see this method :o

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

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.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...