#πŸ”’ Regex/Substring of file paths

16 messages Β· Page 1 of 1 (latest)

vast sedge
#

I have a list of file paths for my images containing

['.../confocal/human_retina/TileScan 003_TileScan_001_s0_z00_ch00.tif', ...]

is there a way where i can get only file paths/ strings containing only s0_z{doesnt matter about the number here}_ch01?

coarse stratusBOT
#

@vast sedge

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

lapis shuttle
#

!e

import re

paths = ['.../confocal/human_retina/TileScan 003_TileScan_001_s0_z00_ch00.tif', 'some/other/path/...']
print([p for p in paths if re.search(r's0_z', p)])
coarse stratusBOT
lapis shuttle
#

finally

#

heck I could have written "s0_z" in p

tame bough
#

Aye. There's the constraint the OP probably means in the basename and to have _ch01 after that.

lapis shuttle
#

🀷

tame bough
#

Maybe using this regexp: s0_z\d+_ch01

lapis shuttle
#

[p for p in paths if re.search(r's0_z', pathlib.Path(p).name)] takes care of some of that

vast sedge
#

this works thank you all

coarse stratusBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

πŸ”’ Regex/Substring of file paths