|
Joined: Oct 2003
Posts: 22
Ameglian cow
|
OP
Ameglian cow
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.
|
|
|
|
Joined: Jan 2003
Posts: 1,063
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 1,063 |
that is what $regex, $regml and $regsub are for...
If it ain't broken, don't fix it!
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
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.
|
|
|
|
Joined: Oct 2003
Posts: 22
Ameglian cow
|
OP
Ameglian cow
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.
|
|
|
|
Joined: Aug 2003
Posts: 1,831
Hoopy frood
|
Hoopy frood
Joined: Aug 2003
Posts: 1,831 |
|
|
|
|
Joined: Oct 2003
Posts: 22
Ameglian cow
|
OP
Ameglian cow
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.
|
|
|
|
Joined: Aug 2003
Posts: 1,831
Hoopy frood
|
Hoopy frood
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.)
|
|
|
|
Joined: Apr 2003
Posts: 414
Fjord artisan
|
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) 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)..
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
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!
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
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.
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
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
|
|
|
|
Joined: Oct 2003
Posts: 22
Ameglian cow
|
OP
Ameglian cow
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.
|
|
|
|
|