Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Regular Expressions, Include & exclude files

Reply
Thread Tools

Regular Expressions, Include & exclude files

 
 
andreasviklund@gmail.com
Guest
Posts: n/a
 
      06-25-2006
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.

 
Reply With Quote
 
 
 
 
Chris
Guest
Posts: n/a
 
      06-25-2006
wrote:
> 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.
>


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.
 
Reply With Quote
 
 
 
 
Alan Moore
Guest
Posts: n/a
 
      07-03-2006
On Sun, 25 Jun 2006 15:17:24 -0500, Chris <>
wrote:

> wrote:
>> 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"
>>
>>

>
>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.


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

"resultset_\\d\\d_\\d\\d(?:_attachment\\d)\\.x ml"

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does Module#include exclude the module's metaclass? John Mair Ruby 8 10-07-2010 12:29 PM
/* #include <someyhing.h> */ => include it or do not include it?That is the question .... Andreas Bogenberger C Programming 3 02-22-2008 10:53 AM
.include & .exclude files in web site KJ ASP .Net 3 11-16-2006 08:49 AM
How to structure a perl program to include and exclude files? Henry Law Perl Misc 3 07-22-2004 06:45 PM
Re: howto use c# regular expression validator to exclude file types Brian Vallelunga ASP .Net 2 07-31-2003 10:27 PM



Advertisments