From 373170b3ee49c4e8a3c49b50be99e32312f8ccbe Mon Sep 17 00:00:00 2001 From: JiFish Date: Tue, 17 May 2022 17:17:42 +0100 Subject: [PATCH] Fix issue with whitespace and negative operators --- ezdice.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ezdice.php b/ezdice.php index 03d0c6f..500039e 100644 --- a/ezdice.php +++ b/ezdice.php @@ -3,6 +3,10 @@ namespace ezdice; class EZDice { + // Magic dice & modifier matching regex + private $re = '(?[\+-])?\s*(?\d+)(?:[dD](?(?:\d+|%))(?:-(?[LlHh]))?)?'; + + // Stores information on last roll private $total = 0; private $states = []; private $modifier = 0; @@ -22,8 +26,7 @@ public function roll(string $diceStr) } // Search for dice groups and modifiers - $re = '/(?[\+-])?(?\d+)(?:[dD](?(?:\d+|%))(?:-(?[LlHh]))?)?/m'; - preg_match_all($re, $diceStr, $matches, PREG_SET_ORDER, 0); + preg_match_all("/{$this->re}/", $diceStr, $matches, PREG_SET_ORDER, 0); // Returning false if no matches found if (sizeof($matches) == 0) return false;