Apr-08-2018, 03:27 PM
The following code demonstrates that the regex provided by Gribouillis seems to answer your original question:
a. Start a new thread providing the minimum of code (and data) that demonstrates your problem.
b. Read the forum rules and provide CODE TAGS for your code.
c. Please provide details concerning your input and your expected output.
Lewis
import os import re RE_FRAME = r'[a-zA-Z_]*(\d+)[a-zA-Z_]*[.]stl' model_subfolder = 'dummy' print("All files in subfolder '{}' follow:".format(model_subfolder)) my_path = os.path.abspath(model_subfolder) for my_file_name in os.listdir(my_path): print (my_file_name) print() print("All files in subfolder '{}' that match the following regex pattern '{}' follow:".format(model_subfolder, RE_FRAME)) my_path = os.path.abspath(model_subfolder) for my_file_name in os.listdir(my_path): if not re.search(RE_FRAME, my_file_name) is None: print(my_file_name)
Output:All files in subfolder 'dummy' follow:
dummy.txt
VS_Subsetup1_Maxillar.stl
VS_Subsetup5_Maxillar.stl
VS_SubsetupXX_Maxillar.stl
All files in subfolder 'dummy' that match the following regex pattern '[a-zA-Z_]*(\d+)[a-zA-Z_]*[.]stl' follow:
VS_Subsetup1_Maxillar.stl
VS_Subsetup5_Maxillar.stl
If you need further assistance you should probably:a. Start a new thread providing the minimum of code (and data) that demonstrates your problem.
b. Read the forum rules and provide CODE TAGS for your code.
c. Please provide details concerning your input and your expected output.
Lewis
To paraphrase: 'Throw out your dead' code. https://www.youtube.com/watch?v=grbSQ6O6kbs Forward to 1:00