RPTools.net

Discussion and Support

Skip to content

It is currently Fri Nov 24, 2017 1:34 pm 






Reply to topic  [ 4 posts ] 

Previous topic | Next topic 

  Print view

Author Message
User avatar  Offline
Cave Troll
 
Joined: Tue Jun 07, 2011 11:08 am
Posts: 90
Location: Canada
 Post subject: ReGex :/
PostPosted: Wed Nov 08, 2017 11:33 am 
Ok, so I've been working on this piece of ReGex for a while now and I'm at my wits end. When I put this formula in https://regexr.com/ it work perfectly but Maptool doesn't like it at all.

Code:
CHA\n([0-9]*).[(\+)].[0-9]*.[(\+)]\s([0-9]*).[(\+)].[0-9]*.[(\+)]\s([0-9]*).[(\+)].[0-9]*.[(\+)]\s([0-9]*).[(\+)].[0-9]*.[(\+)]\s([0-9]*).[(\+)].[0-9]*.[(\+)]\s([0-9]*).[(\+)].[0-9]*.[(\+)]\s


It's for this statblock:

Ghast

Medium undead, chaotic evil

Armor Class 13
Hit Points 36 (8d8)
Speed 30 ft.

STR DEX CON INT WIS CHA
16 (+3) 17 (+3) 10 (+0) 11 (+0) 10 (+0) 8 (-1)
Damage Resistances necrotic
Damage Immunities poison
Condition Immunities charmed, exhaustion, poisoned
Senses darkvision 60 ft., passive Perception 10
Languages Common
Challenge 2 (450 XP)
Stench. Any creature that starts its turn within 5 feet of the ghast must succeed on a DC 10 Constitution saving throw or be poisoned until the start of its next turn. On a successful saving throw, the creature is immune to the ghast's Stench for 24 hours.

Turning Defiance. The ghast and any ghouls within 30 feet of it have advantage on saving throws against effects that turn undead.

ACTIONS
Bite. Melee Weapon Attack: +5 to hit, reach 5 ft., one creature. Hit: 12 (2d8 + 3) piercing damage.

Claws. Melee Weapon Attack: +5 to hit, reach 5 ft., one target. Hit: 10 (2d6 + 3) slashing damage. If the target is a creature other than an undead, it must succeed on a DC 10 Constitution saving throw or be paralyzed for 1 minute. The target can repeat the saving throw at the end of each of its turns, ending the effect on itself on a success.


I'm only trying to extract the main ability's (strength, Dexterity, etc.) without any of the subset's (eg. (+3)) and like I said, it work perfectly on regexr although it DOES say Match #0 but all the Group's following that have the exact number I'm trying to extract. This is the code (mostly stolen from AM) I put in Maptools to try and achieve this:

Code:
[H: id = strfind(statblock, "(?i)(?<!CHA )([0-9]*).[(\+)].[0-9]*.[(\+)]\\s([0-9]*).[(\+)].[0-9]*.[(\+)]\\s([0-9]*).[(\+)].[0-9]*.[(\+)]\\s([0-9]*).[(\+)].[0-9]*.[(\+)]\\s([0-9]*).[(\+)].[0-9]*.[(\+)]\s([0-9]*).[(\+)].[0-9]*.[(\+)]\\s")]

[H, IF(0< getFindCount(id)), CODE: {
   [Strength=getGroup(id, 0, 0)]
   [IF(Strength==""):Strength=10]
   [Dexterity=getGroup(id, 0, 1)]
   [IF(Dexterity==""):Dexterity=10]
   [Constitution=getGroup(id, 2, 1)]
   [IF(Constitution==""):Constitution=10]
   [Intelligence=getGroup(id, 1, 4)]
   [IF(Intelligence==""):Intelligence=10]
   [Wisdom=getGroup(id, 1, 5)]
   [IF(Wisdom==""):Wisdom=10]
   [Charisma=getGroup(id, 1, 6)]
   [IF(Charisma==""):Charisma=10]

}]


I realize the getGroup numbers are all mixed up, I was just trying to extract any number at all! (to no avail.) Any help would be greatly appreciated before I go completely bald. :P

_________________
OOOHH RegEx....YOU BITTER-SWEET BEAST!!!


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7954
Location: Bay Area
 Post subject: Re: ReGex :/
PostPosted: Wed Nov 08, 2017 12:42 pm 
I went ahead and did it how I would do it rather than finding what's wrong with your code.

First I find the pattern of the six stats group together separated by tabs and save that as 1 string. Then I regex that string to pull out the stat digits because regex2 pattern could appear elsewhere in statblock, but 6 in a row doesn't. A possible exception would be a creature with 2 sets of statblocks (which I've seen). This would only get the first set.

Code:
@@ @Test
[Hstatblock "Ghast

Medium undead, chaotic evil

Armor Class 13
Hit Points 36 (8d8) 
Speed 30 ft.

STR    DEX    CON    INT    WIS    CHA
16 (+3)    17 (+3)    10 (+0)    11 (+0)    10 (+0)    8 (-1)
Damage Resistances necrotic
Damage Immunities poison
Condition Immunities charmed, exhaustion, poisoned
Senses darkvision 60 ft., passive Perception 10 
Languages Common
Challenge 2 (450 XP)
Stench. Any creature that starts its turn within 5 feet of the ghast must succeed on a DC 10 Constitution saving throw or be poisoned until the start of its next turn. On a successful saving throw, the creature is immune to the ghast's Stench for 24 hours.

Turning Defiance. The ghast and any ghouls within 30 feet of it have advantage on saving throws against effects that turn undead.

ACTIONS
Bite. Melee Weapon Attack: +5 to hit, reach 5 ft., one creature. Hit: 12 (2d8 + 3) piercing damage.

Claws. Melee Weapon Attack: +5 to hit, reach 5 ft., one target. Hit: 10 (2d6 + 3) slashing damage. If the target is a creature other than an undead, it must succeed on a DC 10 Constitution saving throw or be paralyzed for 1 minute. The target can repeat the saving throw at the end of each of its turns, ending the effect on itself on a success."
]

<!-- 
get stats -->
[
Hregex1 "((\\d+) *[(][\\d +-]+[)]\\t*){6}"]
[
Hregex2 "(\\d+) *[(][\\d +-]+[)]\\t*"]
[
Hid strfind(statblock,regex1)]

[
H, if(getFindCount(id)), code: {
   [
Hstats json.append("[]","Strength","Dexterity","Constitution","Intelligence","Wisdom","Charisma")]
   [
Hmatch getGroup(id,1,0)]
   [
Hid strfind(match,regex2)]
   [
H, foreach(stat,stats), code: {
      [
Hset(stat,getGroup(id,roll.count+1,1))]
   }]
};{
   [
Hassert(0,"Stats in statblock not found.",0)]
}]

!!
 

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7954
Location: Bay Area
 Post subject: Re: ReGex :/
PostPosted: Wed Nov 08, 2017 1:05 pm 
Also, regex stands for regular expression. ReGex should be RegEx if you're going to capitalize. ;)

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Cave Troll
 
Joined: Tue Jun 07, 2011 11:08 am
Posts: 90
Location: Canada
 Post subject: Re: ReGex :/
PostPosted: Wed Nov 08, 2017 3:04 pm 
aliasmask wrote:
Also, regex stands for regular expression. ReGex should be RegEx if you're going to capitalize. ;)


Haha! Well, I'm a newb to all this! :P Thank you sooo much for your help AM! I thought that repeating the formula though the code six times was inefficient but was looking for results. I always like to try and figure this stuff out for myself because obviously the euphoria associated is great, but sometimes I have to step aside and lets the pro's help. Never-the-less, I learned a lot from your example (which of course worked). I'm sure I'll be learning and looking at that one for reference for a while now. I've decided to start taking some courses in programming with Javascript and Python because I get up at 4am to code for a couple hours before I go to work so I obviously have a passion for it! :P

Thanks again! :D

_________________
OOOHH RegEx....YOU BITTER-SWEET BEAST!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 4 posts ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (based on users active over the past 5 minutes)
Most users ever online was 243 on Sun Nov 04, 2012 6:14 am

Users browsing this forum: No registered users and 1 guest





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman