Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

Regular Expressions, Include & exclude files

Thread view: 
andreasviklund@gmail.com - 25 Jun 2006 19:18 GMT
Hi!

I have a javaprogram that should read xml-files from a directory. The
program could contain several types of files but it should only read
files with a certain pattern.

The file names will look like this:

"resultset_27_23.xml"

where the numbers will change, but the rest of the file name is the
same (resultset_XX_XX.xml).

But in the same directory it will also be files with the following
pattern:

"resultset_27_23_attachment1.xml"

Here, the numbers could change in the in the same way as the files
above, and the number after the text (attachment) could also differ
from file to file.Those files should not be read by the program.

I have tried to write a regular expression pattern that only reads the
first file types, and exlcudes the other ones, but it won´t work.

Does anyone have a solution to my problem? It is possible to use either
just one pattern, or two patterns; one for the files that should be
included, and one for the files that should be excluded.
Chris - 25 Jun 2006 21:17 GMT
> Hi!
>
[quoted text clipped - 24 lines]
> just one pattern, or two patterns; one for the files that should be
> included, and one for the files that should be excluded.

I haven't tried it, but this may work:

"resultset_\\d\\d_\\d\\d\\.xml";

\d represents a single digit. \. escapes the dot. All backslashes are
doubled up so they are treated as literals in a Java string.
Alan Moore - 03 Jul 2006 08:34 GMT
>> Hi!
>>
[quoted text clipped - 20 lines]
>\d represents a single digit. \. escapes the dot. All backslashes are
>doubled up so they are treated as literals in a Java string.

That doesn't cover the longer format.  This one does:

"resultset_\\d\\d_\\d\\d(?:_attachment\\d)\\.xml"


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.