We help IT Professionals succeed at work.
Get Started

Regular Expression: Check for substrings in a file name

804 Views
Last Modified: 2012-09-01

Open in new window

Hi,

We use jump uploader (applet)  to upload files to our application.  There is a requirement to block certain files, which contain a certain set of substrings or characters in it. It uses regex to check for file name patterns and here is the regex string it uses to check for patterns:

<param name="uc_fileNamePattern" value="(?i)^(.*\.(?!exe|bat|jpg|gif|png|bmp|tif|tiff|asp|aspx|php|html|js|jar)[^\.]*)|([^\.]+)$">

So the above example blocks files with any of the extensions listed, eg;
exe|bat|jpg|gif|png|bmp|tif|tiff|asp|aspx|php|html|js|jar

We need to modify the regex so those extensions are still blocked, but additionally we want to block filenames that contain any of the terms listed below.

For example we would want to block ‘dropship.pdf’ because the filename contains the term ‘drop’

The new set of characters/Substrings which need to be checked in the file name are:
--
;
/*
char
alter
begin
cast
create
cursor
declare
delete
drop
fetch
insert
kill
open
select
sys
table
update
exec


The regex string provided in the value needs to be modified, so that files  containing above substrings in the file name are blocked. Any help with that will be hugely appreciated.


Thanks In Advance,
Abhinit
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 2 Answers and 28 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE