Skip to content

Commit 0f71535

Browse files
committed
Move compiled regex statements to top-level
1 parent 8b646e5 commit 0f71535

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

deid/dicom/parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
from deid.utils import parse_value, read_json
2424

2525
here = os.path.dirname(os.path.abspath(__file__))
26-
26+
parentheses_hex_tag_format = re.compile(r"\(([0-9A-Fa-f]{4}),([0-9A-Fa-f]{4})\)")
27+
bare_hex_tag_format = re.compile(r"[0-9A-Fa-f]{8}")
2728

2829
class DicomParser:
2930
"""
@@ -461,12 +462,11 @@ def parse_tag_string(tag_string):
461462
4. A tag name (e.g., "PatientID"), rather than a number.
462463
"""
463464
if tag_string.startswith("("):
464-
pattern = re.compile(r"\(([0-9A-Fa-f]{4}),([0-9A-Fa-f]{4})\)")
465-
result = pattern.match(tag_string)
465+
result = parentheses_hex_tag_format.match(tag_string)
466466
return int(f"0x{result.group(1)}{result.group(2)}", base=16)
467467
else:
468468
try:
469-
unannotated_hex_tag = re.compile(r"[0-9A-Fa-f]{8}")
469+
unannotated_hex_tag = bare_hex_tag_format(r"[0-9A-Fa-f]{8}")
470470
if unannotated_hex_tag.match(tag_string):
471471
return int(f"0x{tag_string}", base=16)
472472
else:

0 commit comments

Comments
 (0)