AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

RegExMatch - Between http and ' or "

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
DevX



Joined: 07 Jan 2009
Posts: 43

PostPosted: Tue Jul 07, 2009 3:37 pm    Post subject: RegExMatch - Between http and ' or " Reply with quote

Hey guys,

Can't seem to get this right, I have this "Needle" for regex

Code:

Needle := "http.*?aspx.*?(?=.*""?'?)"
Needle2 := "http.*?aspx""?'?"


But not working as intended (neither of the two). I basically want to match everything between an http and either a ' or a " (quote or double quote)

so like in this
javascript:cmCreateManualLinkClickTagURL('http://www.test.com/todays-special.aspx?ocm=todspc&cm_re=billboard1*ts*~!@#$PositionToken~!@#$','', cG7.cM0[cm_ClientID]);"

it should only get
http://www.hsn.com/todays-special_xh.aspx?ocm=todspc&cm_re=billboard1*ts*~!@#$PositionToken~!@#$'
Back to top
View user's profile Send private message
sinkfaze



Joined: 18 Mar 2008
Posts: 5044
Location: the tunnel(?=light)

PostPosted: Tue Jul 07, 2009 3:47 pm    Post subject: Reply with quote

Like this?

Code:
var = javascript:cmCreateManualLinkClickTagURL('http://www.test.com/todays-special.aspx?ocm=todspc&cm_re=billboard1*ts*~!@#$PositionToken~!@#$','', cG7.cM0[cm_ClientID]);"
MsgBox % RegExReplace(var, ".*?(http[^']+).*","$1")

_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message Send e-mail
DevX



Joined: 07 Jan 2009
Posts: 43

PostPosted: Tue Jul 07, 2009 3:57 pm    Post subject: Reply with quote

I dont even know how thats working... lol

It works in your example, but blows up in mine...

Code:
;Test := "<a href=""http://www.hsn.com/moonlight-festival-blogs_g-125_xg.aspx?reset=1&word=mist"">apples</a><a href=""http://www.hsn.com/moonlight-festival-blogs _g-125_xg.aspx"">oranges</a>"
;Test := "<a href=""http://www.hsn.com/moonlight-festival-blogs_g-125_xg.aspx?reset=1&word=mist"">apples</a><a href=""http://www.hsn.com/moonlight-festival-blogs_g-125_xg.aspx"">oranges</a>"
Test := Clipboard

;Needle := "http.*?aspx.*?(?=.*""?'?)"
Needle := ".*?(http[^']+).*"
Needle2 := "http.*?aspx""?'?"

Start := 1
mCount := 0
Errors := "Please fix these and rerun script`n"
Errors_Default := StrLen(Errors)

loop
{
  FoundPos := RegExMatch(Test, Needle, Output, Start)
  if FoundPos = 0
  {
    FoundPos := RegExMatch(Test, Needle2, Output, Start)
    if FoundPos = 0
      break
  }
  Start := FoundPos + StrLen(Output)
  StringReplace, Output, Output, ",,All
  Test_Space := InStr(Output, A_Space)
  if Test_Space
    Errors := Errors . "Space at #" . Test_Space . " -- " . Output . "`n"
  TmpText%A_Index% := Output
  mCount += 1
}

if (StrLen(Errors) > Errors_Default)
{
  ; Error out
  MsgBox % Errors
}
else
{
  ; Execute
  loop %mCount%
  {
    MsgBox % TmpText%A_Index%
  }
}
Back to top
View user's profile Send private message
DevX



Joined: 07 Jan 2009
Posts: 43

PostPosted: Tue Jul 07, 2009 4:56 pm    Post subject: Reply with quote

Code:
http[^"|']*


Got it =D

Thx for the help
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group