Hi,
I have multiple files with different filenames and want to test out regular expressions.
I can use regexp=".*" to pick up all files, and also regexp=".*\.xxx$" to pick up all files ending with ".xxx".
If I want to pick up files that does not finish with ".xxx" do I use regexp=".*[\^.xxx]$"
Thanks.
4 1452
Hi,
I have multiple files with different filenames and want to test out regular expressions.
I can use regexp=".*" to pick up all files, and also regexp=".*\.xxx$" to pick up all files ending with ".xxx".
If I want to pick up files that does not finish with ".xxx" do I use regexp=".*[\^.xxx]$"
Thanks.
The problem,here, is that you used the escape ('\') which makes the inverse set ('^') a literal. It should be: - >>> import re
-
>>> patt = ".*[^.xxx]$"
-
>>> fname = 'hello.abc'
-
>>> re.match(patt, fname)
-
<_sre.SRE_Match object at 0x03262100>
-
>>> patt = ".*[^.abc]$"
-
>>> re.match(patt, fname)
-
>>> None
bvdet 2,851
Expert Mod 2GB
Hi,
I have multiple files with different filenames and want to test out regular expressions.
I can use regexp=".*" to pick up all files, and also regexp=".*\.xxx$" to pick up all files ending with ".xxx".
If I want to pick up files that does not finish with ".xxx" do I use regexp=".*[\^.xxx]$"
Thanks.
This seems to work: - patt = re.compile(r'.+\.(?!xxx)')
i certainly hope you are just testing regexp, because if you really want to get files that doesn't end with .xxx, you can use the endswith() method.
i certainly hope you are just testing regexp, because if you really want to get files that doesn't end with .xxx, you can use the endswith() method.
That's worth a million, GD. Just one of the reasons that I am so glad that you decide to pop in every now-and-again. Thanks!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Kenneth McDonald |
last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate
feedback, suggestions, and criticism as I work towards finalizing the
API and feature sets. rex is a module intended to make...
|
by: Buddy |
last post by:
Can someone please show me how to create a regular expression to do the
following
My text is set to
MyColumn{1, 100} Test
I want a regular expression that sets the text to the following...
|
by: Neri |
last post by:
Some document processing program I write has to deal with documents
that have headers and footers that are unnecessary for the main
processing part. Therefore, I'm using a regular expression to go...
|
by: Billa |
last post by:
Hi,
I am replaceing a big string using different regular expressions (see
some example at the end of the message). The problem is whenever I
apply a "replace" it makes a new copy of string and I...
|
by: Mike |
last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in
matches. I would like to get what the actual regular expression is.
In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
| |