youtuber Posted February 15, 2018 Posted February 15, 2018 Friends I want to get /autoit" or /autoit/ word from this source Local $RegexSource[3] = ['href="https://www.autoitscript.com/forum/autoit/forum/" />', 'href="https://www.autoitscript.com/forum/autoit" />', 'href="https://www.autoitscript.com/forum/autoit" title="'] my regex pattern $arrayregex = StringRegExp($RegexSource[$i], 'href="' & $aRegexDomain[0] & '.*forum/(.*?)(/[^/|"]+)', 3) And my codes Local $RegexSourceDomainName[3] = ['https://www.autoitscript.com/forum/', 'https://www.autoitscript.com/forum/autoit', 'https://www.autoitscript.com/'] Local $RegexSource[3] = ['href="https://www.autoitscript.com/forum/autoit/forum/" />', 'href="https://www.autoitscript.com/forum/autoit" />', 'href="https://www.autoitscript.com/forum/autoit" title="'] For $i = 0 To UBound($RegexSource) - 1 $aRegexDomain = StringRegExp($RegexSourceDomainName[$i], 'https?://[^/]+', 3) $arrayregex = StringRegExp($RegexSource[$i], 'href="' & $aRegexDomain[0] & '.*forum/(.*?)(/[^/|"]+)', 3) If IsArray($arrayregex) Then ConsoleWrite($aRegexDomain[0] & " : " &$arrayregex[0] & @CRLF) EndIf Next and my console output
ViciousXUSMC Posted February 15, 2018 Posted February 15, 2018 Getting that out of the URL would be easy, but the real question is what is the full scope of the code. How do you expect it to work on other URLs? what is going to be the common capture group you need?
youtuber Posted February 15, 2018 Author Posted February 15, 2018 Obviously this sees my work but this method is too long I want to do with Regex #include <string.au3> Local $RegexSourceDomainName[3] = ['https://www.autoitscript1.com/forum/', 'https://www.autoitscript2.com/forum/autoit', 'https://www.autoitscript3.com/'] Local $RegexSource[3] = ['href="https://www.autoitscript1.com/forum/autoit1/forum/" />', 'href="https://www.autoitscript2.com/forum/autoit2" />', 'href="https://www.autoitscript3.com/forum/autoit3" title="'] For $i = 0 To UBound($RegexSource) - 1 $aRegexDomain = StringRegExp($RegexSourceDomainName[$i], 'https?://[^/]+', 3) $arrayregex = _StringBetween($RegexSource[$i], 'href="' & $aRegexDomain[0] & '/forum/','"') If IsArray($arrayregex) Then $arrayregex = StringReplace($arrayregex[0], "/forum/", "") ConsoleWrite($aRegexDomain[0] & " : " & $arrayregex & @CRLF) EndIf Next
mikell Posted February 15, 2018 Posted February 15, 2018 This shortens the code while getting the same results #include <string.au3> ;~ Local $RegexSourceDomainName[3] = ['https://www.autoitscript1.com/forum/', 'https://www.autoitscript2.com/forum/autoit', 'https://www.autoitscript3.com/'] Local $RegexSource[3] = ['href="https://www.autoitscript1.com/forum/autoit1/forum/" />', 'href="https://www.autoitscript2.com/forum/autoit2" />', 'href="https://www.autoitscript3.com/forum/autoit3" title="'] For $i = 0 To UBound($RegexSource) - 1 $s = StringRegExpReplace($RegexSource[$i], '(https?://[^/]+)/forum/' & '([^/"]+).*', "$1 : $2") ConsoleWrite($s & @CRLF) ;~ $aRegexDomain = StringRegExp($RegexSourceDomainName[$i], 'https?://[^/]+', 3) ;~ $arrayregex = _StringBetween($RegexSource[$i], 'href="' & $aRegexDomain[0] & '/forum/','"') ;~ If IsArray($arrayregex) Then ;~ $arrayregex = StringReplace($arrayregex[0], "/forum/", "") ;~ ConsoleWrite($aRegexDomain[0] & " : " & $arrayregex & @CRLF) ;~ EndIf Next But as said ViciousXUSMC I really don't know how this could be used for a more general purpose 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