Skip to content

Commit

Permalink
Fix the regex NUMBER_PATTERN in _input_base.py (#72)
Browse files Browse the repository at this point in the history
The pipe `|` character has no special meaning inside a character set and will
be matched literally. See Python docs:
https://docs.python.org/3/library/re.html#regular-expression-syntax

`[]`: Used to indicate a set of characters. In a set:
Special characters lose their special meaning inside sets.
For example, `[(+*)]` will match any of the literal characters `'('`, `'+'`, `'*'`, or `')'`.

`[\.]` is indeed redundant, `\.` is sufficient.
  • Loading branch information
singularitti committed Oct 28, 2023
1 parent efe4472 commit c0e3c51
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/qe_tools/parsers/_input_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@

NUMBER_PATTERN = r"""
(?:
[-|+]? # Plus or minus in front of the number (optional)
[-+]? # Plus or minus in front of the number (optional)
(?:\d* # optional decimal in the beginning .0001 is ok, for example
[\.] # There has to be a dot followed by
\. # There has to be a dot followed by
\d+) # at least one decimal
| # OR
(?:\d+ # at least one decimal, followed by
[\.]? # an optional dot
\.? # an optional dot
\d*) # followed by optional decimals
(?:[E|e|d|D][+|-]?\d+)? # optional exponents E+03, e-05, d0, D0
(?:[EedD][+-]?\d+)? # optional exponents E+03, e-05, d0, D0
)
"""

Expand Down

0 comments on commit c0e3c51

Please sign in to comment.