Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regular Expression Help
#8
The following code demonstrates that the regex provided by Gribouillis seems to answer your original question:
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
Reply


Messages In This Thread
Regular Expression Help - by Dazzler - Apr-06-2018, 11:26 AM
RE: Regular Expression Help - by Gribouillis - Apr-06-2018, 12:13 PM
RE: Regular Expression Help - by ljmetzger - Apr-06-2018, 12:40 PM
RE: Regular Expression Help - by Dazzler - Apr-06-2018, 12:53 PM
RE: Regular Expression Help - by Gribouillis - Apr-06-2018, 01:57 PM
RE: Regular Expression Help - by ljmetzger - Apr-06-2018, 02:00 PM
RE: Regular Expression Help - by Dazzler - Apr-06-2018, 02:08 PM
RE: Regular Expression Help - by ljmetzger - Apr-08-2018, 03:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Regular expression help anilrajr 4 350 May-08-2024, 06:18 PM
Last Post: deanhystad
  data validation with specific regular expression shaheen07 0 383 Jan-12-2024, 07:56 AM
Last Post: shaheen07
  Regular Expression search to comment lines of code Gman2233 5 1,746 Sep-08-2022, 06:57 AM
Last Post: ndc85430
  List Creation and Position of Continue Statement In Regular Expression Code new_coder_231013 3 1,736 Jun-15-2022, 12:00 PM
Last Post: new_coder_231013
  Need help with my code (regular expression) shailc 5 2,006 Apr-04-2022, 07:34 PM
Last Post: shailc
  Regular Expression for matching words xinyulon 1 2,218 Mar-09-2022, 10:34 PM
Last Post: snippsat
  regular expression question Skaperen 4 2,578 Aug-23-2021, 06:01 PM
Last Post: Skaperen
  How can I find all combinations with a regular expression? AlekseyPython 0 1,709 Jun-23-2021, 04:48 PM
Last Post: AlekseyPython
  Python Regular expression, small sample works but not on file Acernz 5 3,014 Jun-09-2021, 08:27 PM
Last Post: bowlofred
  Regular expression: cannot find 1st number in a string Pavel_47 2 2,466 Jan-15-2021, 04:39 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020