Skip to content

Conversation

@dutta-alankar
Copy link
Contributor

Simple regex fix for the issue #356

3 7.497932e+00 3.386245e-03 2186 single_file little rho vx1 vx2 vx3 prs tr1 tr2 tr3 Temp ndens PbykB mach
"""
if (match := re.search(r"\d{4}", self.ds.filename)) is not None:
if (match := re.search(r"\d{4}(?!.*\d{4})", self.ds.filename)) is not None:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to find documentation for ?! (negative look-ahead), but I never used this. I'll ask a couple naive questions to make sure I understand how this works.
Surrounding () makes it a non-capturing group, is that right ?
So, the content of match is unchanged when the search does succeed (good), but we now reject file names that have more than one substring matching \d{4} ?

If the goal is to only match the file name (excluding the directory), a simpler fix would be

Suggested change
if (match := re.search(r"\d{4}(?!.*\d{4})", self.ds.filename)) is not None:
if (match := re.search(r"\d{4}", self.ds.basename)) is not None:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neutrinoceros You are right. I wanted to just make this take the last match with 4 digits as it contains the filename. But I think what you are suggesting is also pretty good and will work.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, since this is a pretty different approach I'll open a separate PR then.

@neutrinoceros neutrinoceros linked an issue Jan 16, 2025 that may be closed by this pull request
@neutrinoceros neutrinoceros added bug Something isn't working code: Pluto Specific to Pluto io: hdf5 Specific to xdmf/hdf5 files labels Jan 16, 2025
@dutta-alankar dutta-alankar deleted the patch-1 branch January 17, 2025 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working code: Pluto Specific to Pluto io: hdf5 Specific to xdmf/hdf5 files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trouble with reading h5 filename

2 participants