From c89e3a2926c826b559decd093498417eb7759ef3 Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Thu, 10 Mar 2022 12:34:54 +0000 Subject: [PATCH] revise according to the comments Signed-off-by: Wenqi Li --- monai/bundle/config_reader.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/monai/bundle/config_reader.py b/monai/bundle/config_reader.py index 98f422ea0b..4be7bf0fa8 100644 --- a/monai/bundle/config_reader.py +++ b/monai/bundle/config_reader.py @@ -112,12 +112,12 @@ def split_path_id(cls, src: str) -> Tuple[str, str]: src: source string to split. """ - result = re.compile(cls.suffix_match, re.IGNORECASE).findall(src) - if len(result) != 1: + result = re.compile(rf"(.*{cls.suffix_match}(?=(?:{cls.sep}.*)|$))", re.IGNORECASE).findall(src) + if not result: return "", src # the src is a pure id - items = src.split(result[0]) - # return file path and the - return items[0] + result[0], items[1][len(cls.sep) :] if items[1] != "" else "" + path_name = result[0][0] # at most one path_name + _, ids = src.rsplit(path_name, 1) + return path_name, ids[len(cls.sep) :] if ids.startswith(cls.sep) else "" def read_meta(self, f: Union[PathLike, Sequence[PathLike], Dict], **kwargs): """