mIRC Home    About    Download    Register    News    Help

Print Thread
$regml #353 08/12/02 12:20 PM
Joined: Dec 2002
Posts: 56
W
wshs Offline OP
Babel fish
OP Offline
Babel fish
W
Joined: Dec 2002
Posts: 56
Code:
var %text = <><>< [!wd-mp3 10 - Silent Night .mp3 ]-SpR-[6.1MB N/AKbps N/AKhz N/A]-[0] ><><>
var %regex = /\!.*\.mp3/g
echo -a $regex(%text,%regex)
echo -a $regml(0)


The regex line results in a 1, but the regml line results in a 0 being echoed. Shouldn't the regml also be a 1? If not, what am I doing wrong? I'm trying to extract !trigger file.mp3 from MP3 ads.


Acquire. Analyze. Adapt.
Re: $regml #354 09/12/02 02:20 AM
Joined: Dec 2002
Posts: 12
M
moho Offline
Pikka bird
Offline
Pikka bird
M
Joined: Dec 2002
Posts: 12
$regex returning 1 means the pattern as a whole "matched", which it did. $regml(0) returns 0 because you didn't 'capture' any parts of the pattern for later. Put () around the part of the pattern you wish to capture (e.g. /(\!.*\.mp3)/g) and $regml(0) will return the number of pieces captured. Then you can use $regml(1) etc. to find the actual captured sections.

Re: $regml #355 09/12/02 02:00 PM
Joined: Dec 2002
Posts: 56
W
wshs Offline OP
Babel fish
OP Offline
Babel fish
W
Joined: Dec 2002
Posts: 56
That worked, thanks heaps. I wish to take it further... I want it to match the pattern, but add in something that it can't have .mp3 in it, just at the end. How would I do that? I Tried
/(\!.*^(\.mp3)\.mp3)/g
but it didn't work.


Acquire. Analyze. Adapt.
Re: $regml #356 10/12/02 10:40 AM
Joined: Dec 2002
Posts: 12
M
moho Offline
Pikka bird
Offline
Pikka bird
M
Joined: Dec 2002
Posts: 12
Hrm, there may be a way to do that, but I certainly can't think of an easy one (at least not without knowing exactly what you're trying to do). Your best bet is probably to match the normal way, then check to see if .mp3 is in there twice afterwards (using $count or some such), and ignore it if so.

Re: $regml #357 11/12/02 09:20 AM
Joined: Dec 2002
Posts: 56
W
wshs Offline OP
Babel fish
OP Offline
Babel fish
W
Joined: Dec 2002
Posts: 56
I want to take from ! to the first .mp3, and not have regml return multiple instances of .mp3. In standard regex, I'd be able to use "/.+(\![^ ].*[^[.\.mp3.]].*\.mp3)/g", minus the quotes. I have no idea if I can even do this in mIRC's regex.

If the text had "!somenick somefile.mp3 somefile.mp3", I'd want it to return only "!somenick somefile.mp3", and completely ignore the latter text.

confused


Acquire. Analyze. Adapt.
Re: $regml #358 11/12/02 01:24 PM
Joined: Dec 2002
Posts: 699
N
Nimue Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
/(\!.*?\.mp3)/
? acts as an UNgreedy character, meaning it takes the least possible characters for a match

Re: $regml #359 11/12/02 08:26 PM
Joined: Dec 2002
Posts: 56
W
wshs Offline OP
Babel fish
OP Offline
Babel fish
W
Joined: Dec 2002
Posts: 56
But that doesn't prevent it from returning "!someuser somesong.mp3 encoded-with-.mp3", resulting in a false filename.


Acquire. Analyze. Adapt.
Re: $regml #360 11/12/02 09:14 PM
Joined: Dec 2002
Posts: 699
N
Nimue Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
Actually it does...
//var %a = pretext !someuser somesong.mp3 encoded-with-.mp3 posttext | if ($regex(%a,/(\!.*?\.mp3)/)) echo -a $regml(1)
!someuser somesong.mp3

Re: $regml #361 11/12/02 09:46 PM
Joined: Dec 2002
Posts: 56
W
wshs Offline OP
Babel fish
OP Offline
Babel fish
W
Joined: Dec 2002
Posts: 56
I'll be damned. It does work. Now, if the line has more than 1 exclamation, how would I go about 'encapsulating' from the first ! to the first occurance of .mp3? I currently have "/.+(\![^ ].*?\.mp3)/g", which prevents it from triggering exclamations immediately followed by spaces.

Last edited by wshs; 11/12/02 09:48 PM.

Acquire. Analyze. Adapt.
Re: $regml #362 14/12/02 01:59 PM
Joined: Dec 2002
Posts: 699
N
Nimue Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
confused I'm not quite sure what you want to do here sorry.
" /.+(\!\w.*?\.mp3)/ " maybe.
\w means a 'word' chr.

Re: $regml #363 16/04/03 06:06 AM
Joined: Apr 2003
Posts: 5
S
sergiodf Offline
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
S
Joined: Apr 2003
Posts: 5
Ok, this thread is a little old... sorry

The EOL mark is $
Maybe the regex you need is:
/(\!.*\.mp3$)/g

Last edited by sergiodf; 16/04/03 06:36 AM.