mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2017
Posts: 2
L
Bowl of petunias
OP Offline
Bowl of petunias
L
Joined: Jul 2017
Posts: 2
I am using the following Regex:

Code:
/\b\Qhttp://\E[^\.\s]+\.[^\s]+\.(?:png|jpe?g|bmp|gif)\b/Si


When evaluating, it will succeed for URL's like http://someimagehost.com/picture.jpg, but it will not work for URL's like https://someimagehost.com/picture.jpg

I need to make it support both http and https. I thought that changing it to this would work:

Code:
/\b\Qhttps?://\E[^\.\s]+\.[^\s]+\.(?:png|jpe?g|bmp|gif)\b/Si


But it doesn't match either the first URL shown above, or the second one. It breaks the Regular Expression somehow.

Can somebody help me with getting a Regex that will support both URL's (with http and https). Code snippet I'm using is as follows:

Code:
on *:text:*http*:#:{ 
  var %i = 1
  while ($gettok($1-,%i,32) != $null) {
    if (http isin $gettok($1-,%i,32)) { var %pvurl $gettok($1-,%i,32) }
    inc %i
  }
  var %regex /\b\Qhttp://\E[^\.\s]+\.[^\s]+\.(?:png|jpe?g|bmp|gif)\b/Si
  if (!$regex(%pvurl,%regex)) {
    ; Unsupported URL - Do Sad things
  } 
  else {
    ; Supported URL - Do happy things
  }
} 


Thanks in advance!

Joined: Jul 2017
Posts: 2
L
Bowl of petunias
OP Offline
Bowl of petunias
L
Joined: Jul 2017
Posts: 2
I found the answer myself through trial and error:
Code:
\b^(http|https)\:\/\/[^\.\s]+\.[^\s]+\.(?:png|jpe?g|bmp|gif)\b


Link Copied to Clipboard