Sign in to follow this  
Followers 0
DarkAngel

Get a string of variable length from within a parent string

6 posts in this topic

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

Share this post


Link to post
Share on other sites



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]

Share this post


Link to post
Share on other sites

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 ?

Share this post


Link to post
Share on other sites

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])

Share this post


Link to post
Share on other sites

@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. :)

Share this post


Link to post
Share on other sites

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]

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
Sign in to follow this  
Followers 0