youtuber Posted October 4, 2016 Posted October 4, 2016 (edited) I need the names of sites in a file my experiment has failed #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 October 5, 2016 by youtuber
kylomas Posted October 5, 2016 Posted October 5, 2016 Post an example of your test file... youtuber 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
youtuber Posted October 5, 2016 Author Posted October 5, 2016 @kylomas I do not have any example file
iamtheky Posted October 5, 2016 Posted October 5, 2016 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 , ".")) youtuber 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
mikell Posted October 5, 2016 Posted October 5, 2016 #Include <Array.au3> $text = "https://www.autoitscript.com/forum/" & @crlf& _ "http://autoitscript.test.com/" $aStr = StringRegExp($text, 'https?://(?:www.)?([^.]+)', 3) _ArrayDisplay($aStr) youtuber 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now