Jump to content

Problem extracting subdomain [StringRegExp]


 Share

Recommended Posts

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

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

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

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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

@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

 

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...