This may be a few months old, but if it helps:
Code: Select all
[h: sample1 ="Attack: Glaive +9 melee (1d10+3 plus infernal wound) or claw +8 melee (1d6+2)"]
[h: sample2 ="Attack: Great Big Glaive +9 melee (1d10+3) or claw +8 melee (1d6+2)"]
[h: sample3 ="Attack: Glaive +9 melee (1d10+3 plus infernal wound)"]
[h: sample4 ="Attack: Glaive +9 melee (1d10+3)"]
[h: sample5 ="Attack: Glaive +9 melee (1d10 plus infernal wound)"]
[h:regEx=strformat('[+-](\\d+).*?\\((\\d+d\\d+[+-]?\\d?)')]
[H: id = strfind(sample1,regEx)]
[Output1 = "To Hit:"+getGroup(id,1,1)+" Damage:"+getGroup(id,1,2)+"<br/>"]
[H: id = strfind(sample2,regEx)]
[Output1 = "To Hit:"+getGroup(id,1,1)+" Damage:"+getGroup(id,1,2)+"<br/>"]
[H: id = strfind(sample3,regEx)]
[Output1 = "To Hit:"+getGroup(id,1,1)+" Damage:"+getGroup(id,1,2)+"<br/>"]
[H: id = strfind(sample4,regEx)]
[Output1 = "To Hit:"+getGroup(id,1,1)+" Damage:"+getGroup(id,1,2)+"<br/>"]
[H: id = strfind(sample5,regEx)]
[Output1 = "To Hit:"+getGroup(id,1,1)+" Damage:"+getGroup(id,1,2)+"<br/>"]
Results:
To Hit:9 Damage:1d10+3
To Hit:9 Damage:1d10+3
To Hit:9 Damage:1d10+3
To Hit:9 Damage:1d10+3
To Hit:9 Damage:1d10
The "\\d" means digit, so \\d+ is "One or more digits".
Also, maybe you'll have to parse "1d10+3", maybe just "1d10".
So, "\\d+d\\d+" will match all digits before a letter "d" and after. If it's "10d10", you're covered.
After 1d10, you MAY have a "+1, or -1" or +11 or -13, etc. Or nothing. So we say [+-]? meaning maybe a "+", maybe a "-".
Finally \\d+? which means "maybe a series of one or more digits".
Capturing what you want:
As far as capturing what you want, there are two sets of "( )" that are not escaped (meaning the preceding "\\"). The "\\(" ones mean looks for an actual "(" in the imported text. The parenthesis without preceding "\\" are the ones that say, "Grab what's between "(...)". I made two pairs: the pair wrapping the +9, and the one wrapping the 1d10+3.
When I get groups, I say getGroup(id,1,1) for the first "(...)", and getGroup(id,1,2) for the second.
What will break this search? Well, if damage is, like, just "8" -no roll. It NEEDS a "d" to work, as in "#d#".
To keep things from breaking, I tend to protect myself with an "if" such as this:
Code: Select all
[h: if(getFindCount(id)>0):getGroup(id,1,1)]
Also, if you use getGroup(id,1,0), you get the whole line. It's like the Group "(...)" wraps the whole search from the first character you matched to the last.
Hope that helps.