DarkAngel Posted March 14, 2011 Share Posted March 14, 2011 Hello . I need some ideas regarding how to select a substring of variable length from within a parent string. The substring will be a hotlink . So, it would start with a http:\\ or a https:\\ and end with a space(" ") ,as spaces arent allowed in a link. For ex. if our string is " hello this is the parent link http://www.autoitscript.com/forum/ and this is some extra text. " then the selected string would be "http://www.autoitscript.com/forum/" . Thanks in advance. Link to comment Share on other sites More sharing options...
hannes08 Posted March 14, 2011 Share Posted March 14, 2011 Hi DarkAngel,there are a lot of examples about regular expressions and URLs. So lookup StringRegExp() in the helpfile and google for sth. like "regex url" This should help. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
DarkAngel Posted March 14, 2011 Author Share Posted March 14, 2011 Hi DarkAngel,there are a lot of examples about regular expressions and URLs. So lookup StringRegExp() in the helpfile and google for sth. like "regex url" This should help. Thanks . but by that way i can only check if the url is present in the string or not . But how do i pick that url from the parent string ? Link to comment Share on other sites More sharing options...
Malkey Posted March 14, 2011 Share Posted March 14, 2011 Here are two ways. Local $sParentString = " hello this is the parent link http://www.autoitscript.com/forum/ and this is some extra text. " Local $sSubString = StringRegExpReplace($sParentString, "(?:.*)(http://[^ ]+)(?:.*)", "\1") MsgBox(0, "StringRegExpReplace Substring", $sSubString) ;Or Local $sParentString = " hello this is the parent link http://www.autoitscript.com/forum/ and this is some extra text. " Local $aSubString = StringRegExp($sParentString, "(http://[^ ]+)", 1) MsgBox(0, "StringRegExp Substring", $aSubString[0]) Link to comment Share on other sites More sharing options...
DarkAngel Posted March 14, 2011 Author Share Posted March 14, 2011 @Malkey . Thanks a lot . I missed out on the flags part. I got some regexes for urls from here . Coupled with your example it works great. Link to comment Share on other sites More sharing options...
hannes08 Posted March 14, 2011 Share Posted March 14, 2011 Hi DarkAngel,sometimes a look in the helpfile really helps. This is what I have to tell me a few times a day. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
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