youtuber

A question about regex?

9 posts in this topic

#1 ·  Posted

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="

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

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

1 person likes this

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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

youtuber
Try this pattern   'href="([^#"]+)'
means : "find  href=" , and then grab one or more chars wich are not a quote or hash"
:)

Edited by mikell
1 person likes this

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by youtuber

Share this post


Link to post
Share on other sites

#5 ·  Posted

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)

 

1 person likes this

Share this post


Link to post
Share on other sites

#6 ·  Posted

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

1 person likes this

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

Share this post


Link to post
Share on other sites

#7 ·  Posted

23 minutes ago, iamtheky said:

as expected from me

How true .... so obvious  :D

1 person likes this

Share this post


Link to post
Share on other sites

#8 ·  Posted

@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

 

Share this post


Link to post
Share on other sites

#9 ·  Posted

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.

1 person likes this

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

Share this post


Link to post
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