Skip to content

Commit

Permalink
Merge pull request #112 from olemoign/regex
Browse files Browse the repository at this point in the history
fix: invalid escape sequence
  • Loading branch information
svituz authored Feb 9, 2024
2 parents e6a78a8 + 2550bf7 commit c59242b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions hl7apy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _valid_child_name(child_name, expected_parent):
def _valid_z_message_name(name):
if name is None:
return False
regex = '^z[a-z0-9]{2}_z[a-z0-9]{2}$'
regex = r'^z[a-z0-9]{2}_z[a-z0-9]{2}$'
return re.match(regex, name, re.IGNORECASE) is not None


Expand All @@ -114,7 +114,7 @@ def _valid_z_segment_name(name):


def _valid_z_field_name(name):
regex = '^z[a-z1-9]{2}_\d+$'
regex = r'^z[a-z1-9]{2}_\d+$'
return re.match(regex, name, re.IGNORECASE) is not None


Expand Down
2 changes: 1 addition & 1 deletion hl7apy/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ def parse_subcomponent(text, name=None, datatype='ST', version=None, validation_


def _split_msh(content):
m = re.match("^MSH(?P<field_sep>\S)", content)
m = re.match(r"^MSH(?P<field_sep>\S)", content)
if m is not None: # if the regular expression matches, it is an HL7 message
field_sep = m.group('field_sep') # get the field separator (first char after MSH)
msh = content.split("\r", 1)[0] # get the first segment
Expand Down
2 changes: 1 addition & 1 deletion hl7apy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def get_datetime_info(value):


def _split_offset(value):
offset = re.search('\d*((\+(1[0-4]|0[0-9])|(-(1[0-2]|0[0-9])))([0-5][0-9]))$', value)
offset = re.search(r'\d*((\+(1[0-4]|0[0-9])|(-(1[0-2]|0[0-9])))([0-5][0-9]))$', value)
if offset:
offset = offset.groups()[0]
return value.replace(offset, ''), offset
Expand Down
8 changes: 4 additions & 4 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ def _test_report_file(self, error_type):
with open(self.report_file, 'r') as f:
s = f.read()
if error_type == 'ERROR':
regex = 'Error:.*'
regex = r'Error:.*'
elif error_type == 'WARNING':
regex = 'Warning:.*'
regex = r'Warning:.*'

self.assertTrue(re.search(regex, s))

Expand Down Expand Up @@ -414,9 +414,9 @@ def _test_report_file(self, error_type, present=True):
with open(self.report_file, 'r') as f:
s = f.read()
if error_type == 'ERROR':
regex = 'Error:.*'
regex = r'Error:.*'
elif error_type == 'WARNING':
regex = 'Warning:.*'
regex = r'Warning:.*'
else:
return

Expand Down
2 changes: 1 addition & 1 deletion utils/test_parsing_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def convert(text):
return int(text) if text.isdigit() else text.lower()

def alphanum_key(key):
return [convert(c) for c in re.split('([0-9]+)', key[index])]
return [convert(c) for c in re.split(r'([0-9]+)', key[index])]

return sorted(list_of_lists, key=alphanum_key)

Expand Down

0 comments on commit c59242b

Please sign in to comment.