youtuber

StringRegExp get the names of sites

5 posts in this topic

#1 ·  Posted (edited)

I need the names of sites in a file

c0eef6a8c648414d8280a5be71e8a857.jpg

 

my experiment has failed :doh:

#Include <Array.au3>
$text = FileRead("test.txt")
$aStr = StringRegExp($text, '(?:http|https)s?[^"\r\n]+(.com|.org|.com.tr|.net).*', 3)
_ArrayDisplay($aStr)

or StringRegExpReplace

#Include <Array.au3>
$text = FileRead("test.txt")
$aStr = StringRegExpReplace($text, '(?:http|https)s?[^"\r\n]+(.com|.org|.com.tr|.net).*', '$1')
_ArrayDisplay($aStr)

Edit: or pattern

$ReadString = FileRead("test.txt")
$ReadString = StringReplace($ReadString,@CR,'')
$pattern = '(http://|\.https://|\.www|\.com|\.net|\.org|\.info|\.biz|\.eu|\.fr|\.ch|\.kr|\.edu|\.tr)(.*)'
$ReplaceString = StringRegExpReplace($ReadString, $pattern, "")
   ConsoleWrite(($ReplaceString) & @CRLF)

 

Edited by youtuber

Share this post


Link to post
Share on other sites



#2 ·  Posted

Post an example of your test file...

1 person likes this

Forum Rules         Procedure for posting code

Share this post


Link to post
Share on other sites

#3 ·  Posted

@kylomas I do not have any example file

 

Share this post


Link to post
Share on other sites

#4 ·  Posted

no regex needed, just two splits

#include<array.au3>

;~ $string = "http://test.1sthostname.com/whatever"
;~ $string = "http://test2.2ndhostname2.net"
$string = "http://3test.3rdhostname.info/whomever"
;~ $string = "http://4test.hostnumber4.xxx/wtfever"
;~ $string = "http://test.hostname.google/TLDwtfbbq/forever"

$aStringSplit1 = stringsplit($string , "/" , 2)
_ArrayDelete($aStringSplit1 , ubound($aStringSplit1) - 1)
$aStringSplit2 = stringsplit($aStringSplit1[2] , "." , 2)
_ArrayDelete($aStringSplit2 , ubound($aStringSplit2) - 1)

msgbox(0 , '' , _ArrayToString($aStringSplit2 , "."))

 

1 person likes this

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

Share this post


Link to post
Share on other sites

#5 ·  Posted

:)

#Include <Array.au3>

$text = "https://www.autoitscript.com/forum/" & @crlf& _
        "http://autoitscript.test.com/"

$aStr = StringRegExp($text, 'https?://(?:www.)?([^.]+)', 3)
_ArrayDisplay($aStr)

 

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