Skip to content

Commit 5d56b36

Browse files
committed
Optimize regex usage
1 parent 6f13b6d commit 5d56b36

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/jsonata/tokenizer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
from jsonata import jexception, utils
3434

35+
_NUMBER_PATTERN = re.compile(r"^-?(0|([1-9][0-9]*))(\.[0-9]+)?([Ee][-+]?[0-9]+)?")
36+
3537

3638
class Tokenizer:
3739
operators = {
@@ -264,8 +266,7 @@ def next(self, prefix: bool) -> Optional[Token]:
264266
self.position += 1
265267
raise jexception.JException("S0101", self.position)
266268
# test for numbers
267-
numregex = re.compile("^-?(0|([1-9][0-9]*))(\\.[0-9]+)?([Ee][-+]?[0-9]+)?")
268-
match_ = numregex.search(self.path[self.position:])
269+
match_ = _NUMBER_PATTERN.search(self.path[self.position:])
269270
if match_ is not None:
270271
num = float(match_.group(0))
271272
if not math.isnan(num) and math.isfinite(num):

0 commit comments

Comments
 (0)