mIRC Home    About    Download    Register    News    Help

Print Thread
$sub #67820 14/01/04 07:17 PM
Joined: Oct 2003
Posts: 22
D
DarthAndroid Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Oct 2003
Posts: 22
i know this is asking a lot, but a command where it returns wild text matches:
$sub(<text>,<matchtext>,N)
text and matchtext are obvious
N = * that you want the subsituted text for
so, if i have
$sub(Hi Everybody!,Hi *!,1)
It would return Everybody because in order to do a matchtext Everybody would fit where the 1st (and only) * (asterik) is.
i dont mean to use this like "Hi *" because i could just use $2, but when i have text imeadiately following it (the !) it will still return Everybody.
I have seen this done in several MUD clients (for geting Hp bar status) and cant see why it would be so bad here.

(example) someone says:
Well, right now im hp 412/496 sp 257/453
on *:text:Well, right now im hp */* sp */*:*: {
/set %hp $sub($1-,*hp */* sp */*,1) ;sets %hp to 412
/set %hpmax $sub(hp */* sp */*,2) ;sets %hpmax to 496
/set %sp $sub(hp */* sp */*,3) ;sets %sp to 257
/set %spmax $sub(hp */* sp */*,4) ;sets %spmax to 453


=-=-=-=-=-=-=
Do not meddle in dragons' affairs for you are crunchy and good with ketchup.
Re: $sub #67821 15/01/04 12:44 AM
Joined: Jan 2003
Posts: 1,063
D
Doqnach Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2003
Posts: 1,063
that is what $regex, $regml and $regsub are for...


If it ain't broken, don't fix it!
Re: $sub #67822 15/01/04 12:39 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Yes, but he's suggesting a simplified version using the basic wildcard * (and presumably also ?).

Could be useful assuming it could made to match much faster than the regular expression equivalents.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: $sub #67823 15/01/04 01:59 PM
Joined: Oct 2003
Posts: 22
D
DarthAndroid Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Oct 2003
Posts: 22
yes, that would be my intention. i found info on $regex expresions, but no info on how to use that in $regsub. if you have ever used Portal and messed with the events, you will know what i mean.
if i could find detailed info on $regsub, i might use that but until then, well, im lost.


=-=-=-=-=-=-=
Do not meddle in dragons' affairs for you are crunchy and good with ketchup.
Re: $sub #67824 15/01/04 02:12 PM
Joined: Aug 2003
Posts: 1,831
I
Iori Offline
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
Try here.

Re: $sub #67825 15/01/04 02:25 PM
Joined: Oct 2003
Posts: 22
D
DarthAndroid Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Oct 2003
Posts: 22
nothing on $regsub. ive looked through the $regex tutorial, and i understand the expressions part, but i have no clue how that fits into $regsub


=-=-=-=-=-=-=
Do not meddle in dragons' affairs for you are crunchy and good with ketchup.
Re: $sub #67826 15/01/04 02:34 PM
Joined: Aug 2003
Posts: 1,831
I
Iori Offline
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
Welll specifically: This one
  • Description:
    Terrific tutorial that gives you an in-depth look on Regular Expressions (regml and regsub).
(I haven't read it personally though.)

Re: $sub #67827 15/01/04 04:42 PM
Joined: Apr 2003
Posts: 414
Adrenalin Offline
Fjord artisan
Offline
Fjord artisan
Joined: Apr 2003
Posts: 414
There is a Regular Expressions tutorial from NASA but a litle outdated(last update was on September 1992) smile
A other nice tutorial with some easy to understand examples you can found at here.
Also a good tutorial can be found at perlarchive. But for some reson "unable to resolve (tlc.perlarchive.com)".. MAybe later it will work(i visit that page some day's ago, nop i don't remember the ip :P)..


mIRC Chm Help 6.16.0.3 Full Anchored!
Re: $sub /bb|[^b]{2}/ #67828 15/01/04 06:13 PM
Joined: Feb 2003
Posts: 2,665
Raccoon Online
Hoopy frood
Online
Hoopy frood
Joined: Feb 2003
Posts: 2,665
Here is an example of how you would use $regex and $regml for what you're trying to do.
Note: In Regular Expressions, .* is equivilent to * and . is equivilent to ? . The difference in Regular Expressions is that * is a quantifier for "zero or more" and . is a wildcard for "any character". There are many other wildcards and quantifiers besides these, which is what makes Regular Expressions so much more powerful than Globbing Expressions.

var %s = Hi Everybody!
var %re = [color:red]/
Hi (.*)!/
var %count = $regex(%s,%re)
var %result = $regml(1)[/color]

I used your example to demonstrate how to extract Everybody from your string.

You'll note that a regular expression [typically] begins and ends with /'s, this is so extra options (flags) can be included. If there are no flags, you may omit the /'s. If you wanted the expressoin to be case-insensitive, then you would have used the /i flag.

var %re = [color:red]/Hi (.*)!/i[/color]

Also, text that appears between ( )'s are back-references. In this exercise, the text being matched by .* is stored as a back-reference, and can be recalled using the $regml identifier.

Another thing you should be aware of are meta-characters which are special characters in regular expressions, like wildcards. You can escape these characters with \ if you want to use that literal character, like . would be \. . This only applies to non-alphanum characters however, as placing a \ before a letter or number will usually create a meta-character instead. For instance, \s stands for Space or Tab, and \S stands for any Non-Space/Tab character.

This crash course into Regular Expressions has been brought to you in part by...

/Raccoon/

(Thanks starbucks!)

Last edited by Raccoon; 15/01/04 08:11 PM.

Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: $sub /bb|[^b]{2}/ #67829 15/01/04 07:53 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
That would have to be /Hi (.*)!/ if you actually wanted it to match something.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: $sub /bb|[^b]{2}/ #67830 16/01/04 12:32 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Quote:
If there are no flags, you may omit the /'s.
True, except when the pattern begins with the letter "m". In that case, the pattern is messed up because m is used to define the pattern quotes. To avoid this problem, one must include the /'s.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: $sub /bb|[^b]{2}/ #67831 16/01/04 12:37 AM
Joined: Oct 2003
Posts: 22
D
DarthAndroid Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Oct 2003
Posts: 22
thankyou this is exactly what i needed. you are a life saver


=-=-=-=-=-=-=
Do not meddle in dragons' affairs for you are crunchy and good with ketchup.