|
Iceclaw Apprentice
Joined: 11 Sep 2005 Posts: 124
|
Posted: Tue Dec 13, 2005 6:24 am
Extracting Numerical Data from a String |
Trying to extract the various numbers from this line, captured as a string because sometimes there are white spaces
Basically, how can ignore any whitespaces (" ") just inside the start of the brackets match ie, could begin with "[ " or "[(%s)#"
Source String:
Hit dice: [230d4 + 0] Damage dice: [ 2d35 + 23] Mana dice: [ 1d1 + 99]
Trigger in Progress:^Hit dice:(%s)~[(*)~](%s)Damage dice~:(%s)~[(*)~](%s)Mana dice:(%s)~[(*)~]$
Trigger currently does:
#addkey Mob_Db_Add Hit_Dice {%2}
#addkey Mob_Db_Add Damage_Dice {%5}
#addkey Mob_Db_Add Mana_Dice {%8}
What I'd like it to do is match off of something more like .
Trigger:
^Hit dice:(%s)~[(%s)(%d)d(%d)(%s)+(%s)(%d)~](%s)Damage dice~:(%s)~[(%s)(%d)d(%d)(%s)+(%s)(%d)~](%s)Mana dice:(%s)~[(%s)(%d)d(%d)(%s)+(%s)(%d)~]$ |
|
|
|
Taz GURU
Joined: 28 Sep 2000 Posts: 1395 Location: United Kingdom
|
Posted: Tue Dec 13, 2005 12:54 pm |
You're not wanting to capture the spaces so you don't need to surround them with round brackets. Try ~[{ | | |}(%d)d(%d)%s+%s(%d)~] for the dice rolls.
|
|
_________________ Taz :) |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Wed Dec 14, 2005 8:46 am |
Just capture with * and then get rid of the spaces with %replace("%nn"," ","")
#TRIGGER {^Hit dice:%s~[(*)~]%sDamage dice~:%s~[(*)~]%sMana dice:%s~[(*)~]$} {
#addkey Mob_Db_Add Hit_Dice {%replace("%1"," ","")}
#addkey Mob_Db_Add Damage_Dice {%replace("%1"," ","")}
#addkey Mob_Db_Add Mana_Dice {%replace("%1"," ","")}
}
Alternately I believe the %dice functions will ignore spaces, and %eval definitely does, so you could use something like this.
#TRIGGER {^Hit dice:%s~[{%s|}([0-9d])(*)~]%sDamage dice~:%s~[{%s|}([0-9d])(*)~]%sMana dice:%s~[{%s|}([0-9d])(*)~]$} {
#addkey Mob_Db_Add Hit_Avg {%eval(%diceavg(%1)%2)}
#addkey Mob_Db_Add Damage_Avg {%eval(%diceavg(%3)%4)}
#addkey Mob_Db_Add Mana_Avg {%eval(%diceavg(%5)%6)}
} |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums
Last edited by Vijilante on Wed Dec 14, 2005 11:12 pm; edited 1 time in total |
|
|
|
Taz GURU
Joined: 28 Sep 2000 Posts: 1395 Location: United Kingdom
|
Posted: Wed Dec 14, 2005 2:49 pm |
When I looked at this I tried to get {%s|} to work and it didn't hence why I used { | | |} to deal with 0 to 3 spaces. Is there a trigger option that makes {%s|} work? I believe that the help on triggers says it's not possible.
Pattern Matching wrote: |
{val1|val2|val3|...} match any of the specified strings can not use other wildcard inside this |
|
|
_________________ Taz :) |
|
|
|
Larkin Wizard
Joined: 25 Mar 2003 Posts: 1113 Location: USA
|
Posted: Wed Dec 14, 2005 2:53 pm |
If you use a regular expression, \s* will match 0 or more spaces. I find it to be a better option than %s in many cases.
|
|
|
|
Taz GURU
Joined: 28 Sep 2000 Posts: 1395 Location: United Kingdom
|
Posted: Wed Dec 14, 2005 3:43 pm |
Absolutely and is by far the best way to go. Still I'm interested to know if it possible to do {%s|} using zMUD patterns.
|
|
_________________ Taz :) |
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: Wed Dec 14, 2005 3:55 pm |
Yes, but you have to enable wildcards in ranges (or something like that) somewhere in zmuds prefrences page
|
|
|
|
Taz GURU
Joined: 28 Sep 2000 Posts: 1395 Location: United Kingdom
|
Posted: Wed Dec 14, 2005 4:07 pm |
Most excellent, one to store in the memory banks.
Vij your post needs editing so the %diceagv lines become %diceavg, when done remove this line from my post.
Vijilante--edit done. I don't mind admitting my mistakes. |
|
_________________ Taz :) |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Wed Dec 14, 2005 11:16 pm |
The use of wildcards in {} portions of the pattern was added in the 7.x versions of zMud. That particular entry in the help dates back to when I first editted it in the 6.2x betas. Maybe someday I will get around to correcting that.
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
|
|