Jump to content

Get a string of variable length from within a parent string


Recommended Posts

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

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

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

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...