mIRC Home    About    Download    Register    News    Help

Print Thread
#269005 26/05/21 07:18 PM
Joined: Jan 2021
Posts: 32
T
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Jan 2021
Posts: 32
I have made a regex which should work in most languages. But it seems like mIRC don't like it.

Let's just get this random line which I'm testing against:
Code
Vestibulum ante ipsum primis in faucibus orci https://www.youtube.com/watch?v=5gGjRcGdELs ipsum primis in faucibus orci luctus et ultrices posuere


And the working Regex for most languages:
Code
https:\/\/www\.youtube\.com\/watch\?v=[0-9a-zA-Z-_]{6,20}


I guess this Regex is not working in mIRC. If someone know how I should do this in Regex. Please tell me what I do wrong and how the Regex you made works.
I know regex but for mIRC it seems special.

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
If you have a comma in your text or pattern, you need to either place it into a %variable or else use string1 $+ $chr(44) $+ string2 etc.

//var %msg Vestibulum ante ipsum primis in faucibus orci https://www.youtube.com/watch?v=5gGjRcGdELs ipsum primis in faucibus orci luctus et ultrices posuere , %pattern (https:\/\/www\.youtube\.com\/watch\?v=[0-9a-zA-Z-_]{6,20}) | echo -a matches: $regex(%msg,%pattern) 1st capture group: $regml(1)

Joined: Jan 2021
Posts: 32
T
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Jan 2021
Posts: 32
Originally Posted by maroon
If you have a comma in your text or pattern, you need to either place it into a %variable or else use string1 $+ $chr(44) $+ string2 etc.

//var %msg Vestibulum ante ipsum primis in faucibus orci https://www.youtube.com/watch?v=5gGjRcGdELs ipsum primis in faucibus orci luctus et ultrices posuere , %pattern (https:\/\/www\.youtube\.com\/watch\?v=[0-9a-zA-Z-_]{6,20}) | echo -a matches: $regex(%msg,%pattern) 1st capture group: $regml(1)


I don't see much changed only the "(" and ")" was added. Can you tell me why they needed to be added to mIRC Regexp?

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
The regex doesn't need to change at all. What matters is you store it in a a variable. You can't use the string directly in $regex when it contain a comma because mIRC uses a comma to delineate parameters.

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
The parenthesis are needed if you want to have a capture group which allows you to return the actual url. Without the parenthesis, $regex can only return a 1 or 0 to indicate yes/no whether a url is present. (with /pattern/g it can return greater than 1).

However, because your pattern has the {6,20} containing the comma, mIRC thinks the literal comma indicates another parameter, so it either does something you don't want it to do, or else it errors because of thinking there's too many parameters. For example, the next example tests a string to see if it's base64. The 1st one returns 0 because the literal comma in {2,} confuses $regex. However the 2nd one works fine because the literal comma is placed into the %variable, and so $regex doesn't see the literal comma as an indicator of an extra parameter.

//var %string deadbeef | echo -a $regex(%string,/^[a-zA-Z0-9\/+]{2,}$/)
//var %pattern /^[a-zA-Z0-9\/+]{2,}$/ , %string deadbeef | echo -a $regex(%string,%pattern)

If you don't want to park your pattern into a %variable, you'd need to use $chr(44) like:

//var %string deadbeef | echo -a $regex(%string,/^[a-zA-Z0-9\/+]{2 $+ $chr(44) $+ }$/)

Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
A small example of using regex within mIRC:

Code
var %test_text = Vestibulum ante ipsum primis in faucibus orci https://www.youtube.com/watch?v=5gGjRcGdELs ipsum primis in faucibus orci luctus et ultrices posuere https://www.youtube.com/watch?v=dQw4w9WgXcQ

;; Note: \Q...\E escapes an entire block of a regex pattern so individual characters do not need to be escaped
var %pattern = /(\Qhttps://www.youtube.com/watch?v=\E[0-9a-zA-Z-_]{6,20})/ig

;; Test if the text has a yt link: $regex()
;; This also returns the number of times the regex matched in the string
echo -a HasYouTubeLink: $regex(hasytlink, %test_text, %pattern)

;; Get the number of matches
echo -a Number of Youtube Links: $regml(hasytlink, 0)

;; Get first match
echo -a First Link: $regml(hasytlink, 1)

;; Get second link
echo -a Second Link: $regml(hasytlink, 2)


I am SReject
My Stuff
Joined: Jan 2021
Posts: 32
T
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Jan 2021
Posts: 32
Thanks for the information about regex.


Link Copied to Clipboard