mIRC Home    About    Download    Register    News    Help

Print Thread
#210650 22/03/09 06:27 PM
Joined: Dec 2006
Posts: 7
T
Tony311 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Dec 2006
Posts: 7
I'm wondering how you add a space (" ") to a variable or between variables when using the $+ identifier.

For example, say I have two variables

%one = One
%two = Two

Let's say I need it returned like "One Two". However, if I do this:

echo %one $+ %two

It returns "OneTwo" without the space between them. How do I add a space between the two variables?

Help is much appreciated

Tony311 #210651 22/03/09 06:44 PM
Joined: Dec 2008
Posts: 95
A
Babel fish
Offline
Babel fish
A
Joined: Dec 2008
Posts: 95
echo %one %two

?

Joined: Dec 2006
Posts: 7
T
Tony311 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Dec 2006
Posts: 7
Thanks! That worked.

Tony311 #210656 22/03/09 07:42 PM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Or: echo $+(%one,$chr(32),%two)

Tomao #210659 22/03/09 08:12 PM
Joined: Dec 2006
Posts: 7
T
Tony311 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Dec 2006
Posts: 7
OK< another question... I'm trying to write a script to intercept URLs in text and do some stuff with the URL, eventually adding some text after the URL. For example..


<Tony311> this is a url: http://google.com Now go visit it

should end up being

<Tony311> this is a url: http://google.com [text] Now go visit it

Is there any way to get the string that matched $regex? Like, "some stuff here", where the regex string is stuff.* would return "stuff here". But I can't find any way to get the matched string. Currently I'm trying to use $left and $right, but it's getting complicated.

Tony311 #210662 22/03/09 08:45 PM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
You can use back references. Basic example:
Code:
if $regex(some stuff here,/(stuff.*)/) { echo -a captured: $regml(1) }

If you give a concrete example, this could be improved smile

Horstl #210663 22/03/09 08:54 PM
Joined: Dec 2006
Posts: 7
T
Tony311 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Dec 2006
Posts: 7
Okay, I can do that. I'm writing a script that intercepts URLs in channel text, opens a socket to the URL, and adds the title of the page after the URL, so you'd end up with something like

<Tony311> go to http://mirc.com [mIRC: Internet Relay Chat client] to get mirc

I already have all of the socket stuff done, I'm just working on intercepting URLs now. Each time someone says something, the script will use regex to find any URLs, then (this is what I need the matched text for) it will take the matched URL, return the title, and echo the timestamp, username, message, the url, and the title in place of the original message.

This is the regex i've been looking at (found it on some site):

https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?

The problem is, if I use $regml, it only returns the domain name, not the request string (/whatever/whatever.something.php) or the prefix (http://).

Tony311 #210665 22/03/09 09:33 PM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Hum, I roughly modified this regex to capture the whole url with prefix:
- adding a capturing set ot round brackets at the start and at the end
- making the sub-sets of round brackets non-capturing by adding "?:" at their start
- escaping the /-slashes as they would be interpreted as a metachar, so you can use the g parameter to capture multiple urls on one line

To: /(https?:\/\/(?:[-\w\.]+)+(?::\d+)?(?:\/(?:[\w/_\.]*(?:\?\S+)?)?)?)/g

Code:
alias regtest {
  var %text = http://www.mirc.com/mirc.html sometext https://forums.mirc.com/ubbthreads.php sometext www.mirc.com
  if $regex(%text,/(https?:\/\/(?:[-\w\.]+)+(?::\d+)?(?:\/(?:[\w/_\.]*(?:\?\S+)?)?)?)/g) {
    echo -a captured urls: $regml(0)
    var %n = 1
    while ($regml(%n)) {
      echo -a %n : $v1
      inc %n
    }
  }
}
captured urls: 2
1 : http://www.mirc.com/mirc.html
2 : https://forums.mirc.com/ubbthreads.php

It won't capture the last url, as this one doesn't include a http(s) prefix - don't know what exactly you'd like to match.
Furthermore, I'm no regex pro. And this one really doesn't look neat. For sure someone else will be able to improve it a lot smile

Horstl #210666 22/03/09 09:44 PM
Joined: Dec 2006
Posts: 7
T
Tony311 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Dec 2006
Posts: 7
Thanks a lot! I'll get to work right away.

Last edited by Tony311; 22/03/09 09:45 PM.
Tony311 #210668 22/03/09 09:50 PM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
This regex will echo the whole set of an url link said in a channel. I'm unclear as to what you're wanting to get though.
Code:
on *:TEXT:*:#: {
  if ($regex($1-,/(?<=^| )((?>[a-zA-Z-0-9]{3,8}:\/\/|www\.)\S+)/g)) { echo -a $regml(1) }
}

Tomao #210675 23/03/09 12:28 AM
Joined: Dec 2006
Posts: 7
T
Tony311 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Dec 2006
Posts: 7
Ok I'm using Horstl's code, it works pretty fine except for two things:

1. If the URL points to a redirected page, the socket doesn't follow the redirect and instead returns a 301 or 302 response.

2. The regex string isn't recognizing domains such as co.uk
EDIT: Turns out it's linefeeds causing this problem, the co.uk part is probably fine. So if a page looks like:

<title>
Page Title
</title>

It's not recognizing it. Anyone know a workaround?

I've tried replacing linefeeds with whitespace in the returned text but apparently, the response event runs once for every line of HTML returned - so if the titlew tags are on separate lines, there's no way to compare them and get the center, unless a much more complicated setup is used to watch if there's a title on one line, and save each line, and if it finds a </title>, return the last line, etc. etc. etc. I'm hoping there's an easier way around this.

I'm considering setting up another regex and if it finds a redirect, it returns the link and opens a new socket to the new, redirected URL.

Last edited by Tony311; 23/03/09 04:20 AM.

Link Copied to Clipboard