mIRC Homepage
Posted By: DarthAndroid $sub - 14/01/04 07:17 PM
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
Posted By: Doqnach Re: $sub - 15/01/04 12:44 AM
that is what $regex, $regml and $regsub are for...
Posted By: starbucks_mafia Re: $sub - 15/01/04 12:39 PM
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.
Posted By: DarthAndroid Re: $sub - 15/01/04 01:59 PM
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.
Posted By: Iori Re: $sub - 15/01/04 02:12 PM
Try here.
Posted By: DarthAndroid Re: $sub - 15/01/04 02:25 PM
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
Posted By: Iori Re: $sub - 15/01/04 02:34 PM
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.)
Posted By: Adrenalin Re: $sub - 15/01/04 04:42 PM
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)..
Posted By: Raccoon Re: $sub /bb|[^b]{2}/ - 15/01/04 06:13 PM
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!)
Posted By: starbucks_mafia Re: $sub /bb|[^b]{2}/ - 15/01/04 07:53 PM
That would have to be /Hi (.*)!/ if you actually wanted it to match something.
Posted By: qwerty Re: $sub /bb|[^b]{2}/ - 16/01/04 12:32 AM
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.
Posted By: DarthAndroid Re: $sub /bb|[^b]{2}/ - 16/01/04 12:37 AM
thankyou this is exactly what i needed. you are a life saver
© mIRC Discussion Forums