Jump to content
youtuber

Problem extracting subdomain [StringRegExp]

Recommended Posts

youtuber

Hello, I need subdomains
But there is no response in GUICtrlSetData($Edit2, $aSubdomain[$i] & @CRLF, 1)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $aListUrl = "https://www.autoitscript.com/forum/" & @crlf & _
'https://www.autoitscript.com' & @crlf & _
'https://test.blogspot.com.tr' & @crlf & _
'https://test.blogspot.com' & @crlf & _
'http://test.blogspot.com.tr' & @crlf & _
'http://test.blogspot.com' & @crlf & _
'test.blogspot.com.tr'

$Form1 = GUICreate("Form1", 830, 668)
$Edit1 = GUICtrlCreateEdit("", 32, 48, 353, 545)
GUICtrlSetData($Edit1, $aListUrl)
GUICtrlSetLimit($Edit1, 90000000)
$Edit2 = GUICtrlCreateEdit("" & @CRLF, 400, 48, 401, 553, BitOR($ES_MULTILINE, $ES_AUTOVSCROLL, $WS_VSCROLL))
GUICtrlSetData(-1, "")
GUICtrlSetLimit($Edit2, 90000000)
$ExtractSubDomain = GUICtrlCreateButton("Extract", 32, 616, 75, 25)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $ExtractSubDomain
$TestString = StringSplit(StringStripCR(GUICtrlRead($Edit1)), @LF, 2)
$aSubdomain = StringRegExp($TestString, 'https?:\/\/[\w+\.]+[blogspot.com][blogspot.com.tr]', 3)
For $i = 0 To UBound($aSubdomain) - 1
GUICtrlSetData($Edit2, $aSubdomain[$i] & @CRLF, 1)
Next
    EndSwitch
WEnd

 

Edited by youtuber

Share this post


Link to post
Share on other sites
kylomas

youtuber,

This is what I think you are trying to do.  Note sub domain is the 1st node after protocol.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <array.au3>

Global $aListUrl = "https://www.autoitscript.com/forum/" & @CRLF & _
        'https://www.autoitscript.com' & @CRLF & _
        'https://test.blogspot.com.tr' & @CRLF & _
        'https://test.blogspot.com' & @CRLF & _
        'http://test.blogspot.com.tr' & @CRLF & _
        'http://test.blogspot.com' & @CRLF & _
        'test.blogspot.com.tr'

$Form1 = GUICreate("Form1", 830, 668)
$Edit1 = GUICtrlCreateEdit("", 32, 48, 353, 545)
GUICtrlSetData($Edit1, $aListUrl)
GUICtrlSetLimit($Edit1, 90000000)
$Edit2 = GUICtrlCreateEdit("" & @CRLF, 400, 48, 401, 553, BitOR($ES_MULTILINE, $ES_AUTOVSCROLL, $WS_VSCROLL))
GUICtrlSetData(-1, "")
GUICtrlSetLimit($Edit2, 90000000)
$ExtractSubDomain = GUICtrlCreateButton("Extract", 32, 616, 75, 25, $BS_DEFPUSHBUTTON)
GUISetState(@SW_SHOW)
ControlFocus('', '', $ExtractSubDomain)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

            ; this works and follows the technique you were using

;~      Case $ExtractSubDomain
;~          $TestString = StringSplit(StringStripCR(GUICtrlRead($Edit1)), @LF, 2)
;~          ;_ArrayDisplay($TestString)
;~          For $i = 0 To UBound($TestString) - 1
;~              $sSubdomain = StringRegExp($TestString[$i], '(?:https?:\/\/)?(.*?)\.', 3)
;~              If Not @error Then GUICtrlSetData($Edit2, $sSubdomain[0] & @CRLF, 1)
;~          Next

            ; This is a cleaner, more efficient way

        Case $ExtractSubDomain
            $aSubdomain = StringRegExp($aListUrl, '(?im)^(?:https?:\/\/)?(.*?)\.', 3)
            For $i = 0 To UBound($aSubdomain) - 1
                GUICtrlSetData($Edit2, $aSubdomain[$i] & @CRLF, 1)
            Next

    EndSwitch
WEnd

  I corrected several mistakes in your code, most notably, trying to reference an array as a simple variable (no index)

$aSubdomain = StringRegExp($TestString, 'https?:\/\/[\w+\.]+[blogspot.com][blogspot.com.tr]', 3)

Did you read the comments I wrote in your previous threads regarding variable naming conventions?  You will find more willing help if you try to use them.

kylomas

  • Like 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

Share this post


Link to post
Share on other sites
youtuber

http https including www

What I need is

https://test.blogspot.com.tr
https://test.blogspot.com
http://test.blogspot.com.tr
http://test.blogspot.com
test.blogspot.com.tr
test.blogspot.com
or
www.asdf.blogspot.com
www.asdf.blogspot.com.tr
https://www.test.blogspot.com.tr
https://www.test.blogspot.com

 

Share this post


Link to post
Share on other sites
ripdad

youtuber,

It's not making any sense.

You will have to be more specific.

 

Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites
youtuber

@ripdadI indicated with the arrow mark what I needed

Spoiler

By8NpQ.png

 

Edited by youtuber

Share this post


Link to post
Share on other sites
kylomas

youtuber,

You want all url's with "BlogSpot"?

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

Share this post


Link to post
Share on other sites
ripdad

youtuber,

And where is the entries for autoitscript.com?

 

 


"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites
youtuber
6 minutes ago, kylomas said:

youtuber,

You want all url's with "BlogSpot"?

kylomas

 

Yes I want all blogspot URLs

Spoiler

4G0QEp.jpg

 

Edited by youtuber

Share this post


Link to post
Share on other sites
kylomas

youtuber,

Just change the SRE...

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <array.au3>

Global $aListUrl = "https://www.autoitscript.com/forum/" & @CRLF & _
        'https://www.autoitscript.com' & @CRLF & _
        'https://test.blogspot.com.tr' & @CRLF & _
        'https://test.blogspot.com' & @CRLF & _
        'http://test.blogspot.com.tr' & @CRLF & _
        'http://test.blogspot.com' & @CRLF & _
        'test.blogspot.com.tr'

$Form1 = GUICreate("Form1", 830, 668)
$Edit1 = GUICtrlCreateEdit("", 32, 48, 353, 545)
GUICtrlSetData($Edit1, $aListUrl)
GUICtrlSetLimit($Edit1, 90000000)
$Edit2 = GUICtrlCreateEdit("" & @CRLF, 400, 48, 401, 553, BitOR($ES_MULTILINE, $ES_AUTOVSCROLL, $WS_VSCROLL))
GUICtrlSetData(-1, "")
GUICtrlSetLimit($Edit2, 90000000)
$ExtractSubDomain = GUICtrlCreateButton("Extract", 32, 616, 75, 25, $BS_DEFPUSHBUTTON)
GUISetState(@SW_SHOW)
ControlFocus('', '', $ExtractSubDomain)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

            ; this works and follows the technique you were using

;~      Case $ExtractSubDomain
;~          $TestString = StringSplit(StringStripCR(GUICtrlRead($Edit1)), @LF, 2)
;~          ;_ArrayDisplay($TestString)
;~          For $i = 0 To UBound($TestString) - 1
;~              $sSubdomain = StringRegExp($TestString[$i], '(?:https?:\/\/)?(.*?)\.', 3)
;~              If Not @error Then GUICtrlSetData($Edit2, $sSubdomain[0] & @CRLF, 1)
;~          Next

            ; This is a cleaner, more efficient way

        Case $ExtractSubDomain
            ;$aSubdomain = StringRegExp($aListUrl, '(?im)^(?:https?:\/\/)?(.*?)\.', 3)
            $aSubdomain = StringRegExp($aListUrl, '.*?blogspot.*', 3)
            For $i = 0 To UBound($aSubdomain) - 1
                GUICtrlSetData($Edit2, $aSubdomain[$i] & @CRLF, 1)
            Next

    EndSwitch
WEnd

kylomas

  • Like 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

Share this post


Link to post
Share on other sites
youtuber

@kylomas Thank you
Is my arrangement correct?

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <array.au3>

Global $aListUrl = "https://www.autoitscript.com/forum/" & @CRLF & _
        'https://www.autoitscript.com' & @CRLF & _
        'https://test.blogspot.com.tr' & @CRLF & _
        'https://test.blogspot.com' & @CRLF & _
        'http://test.blogspot.com.tr/asdfasdf' & @CRLF & _
        'http://test.blogspot.com' & @CRLF & _
        'test.blogspot.com.tr'

$Form1 = GUICreate("Form1", 830, 668)
$Edit1 = GUICtrlCreateEdit("", 32, 48, 353, 545)
GUICtrlSetData($Edit1, $aListUrl)
$Edit2 = GUICtrlCreateEdit("" & @CRLF, 400, 48, 401, 553, BitOR($ES_MULTILINE, $ES_AUTOVSCROLL, $WS_VSCROLL))
GUICtrlSetData(-1, "")
$ExtractSubDomain = GUICtrlCreateButton("Extract", 32, 616, 75, 25, $BS_DEFPUSHBUTTON)
GUISetState(@SW_SHOW)
ControlFocus('', '', $ExtractSubDomain)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

     Case $ExtractSubDomain
         $TestString = StringSplit(StringStripCR(GUICtrlRead($Edit1)), @LF, 2)
         ;_ArrayDisplay($TestString)
         For $i = 0 To UBound($TestString) - 1
             $sSubdomain = StringRegExp($TestString[$i], '.*?blogspot.*', 3)
             If Not @error Then GUICtrlSetData($Edit2, $sSubdomain[0] & @CRLF, 1)
         Next
    EndSwitch
WEnd

 

Share this post


Link to post
Share on other sites
kylomas

youtuber,

Yes, for that source. 

kylomas

  • Like 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

Share this post


Link to post
Share on other sites
ripdad

Danp2, Ok.

kylomas, Thanks

youtuber, Glad you got it worked out.

  • Like 1

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites
kylomas

youtuber,

Are you reading what I post and the comments in the code?

kylomas

  • Like 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

Share this post


Link to post
Share on other sites
youtuber

Yes, I respect your notes, I respect you, thank you
I read it again and again
my english is not very good but i'm trying to learn :)

Share this post


Link to post
Share on other sites
kylomas

youtuber,

No problem, I suspected a language issue.  Let me encourage you to read the wiki articles regarding arrays.

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

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.