Can someone suggest regex for this requirement

Tips on writing regular expressions for searching the post list

Moderators: Quade, dexter

Can someone suggest regex for this requirement

Postby yungblud » Sat Nov 08, 2003 9:37 am

I want to avoid downloading index jpegs because I never require them.

Can someone suggest a regex expression to use in the Reject Subject Filter and Reject Filename Filter for jpeg files which begin or end with one or more exclamation marks.

For example:
!fred.jpg
!william.jpg
!!fred.jpg
!!william.jpg

(or ending in ".jpeg" too).

If it is possible for the regex to require an "x" to be present in the text portion of the file name (which begins with an exclamation mark) then so much the better as this will help to better locate index files.

Perhaps I should also eliminate file names which *end* in one or more exclamation marks and which also contain an "x" in the file name. If there is a second regex I can use for this then thank you.
User avatar
yungblud
Seasoned User
Seasoned User
 
Posts: 168
Joined: Fri Sep 19, 2003 12:29 pm

Re: Can someone suggest regex for this requirement

Postby Smite » Sun Nov 09, 2003 6:31 am

yungblud wrote:Can someone suggest a regex expression to use in the Reject Subject Filter and Reject Filename Filter for jpeg files which begin or end with one or more exclamation marks.

For example:
!fred.jpg
!william.jpg
!!fred.jpg
!!william.jpg


\!.*\.jpg would catch all of those.

yungblud wrote:(or ending in ".jpeg" too).


\.jpeg would catch that.

yungblud wrote:If it is possible for the regex to require an "x" to be present in the text portion of the file name (which begins with an exclamation mark) then so much the better as this will help to better locate index files.


\!.*x.*\.jpeg

yungblud wrote:Perhaps I should also eliminate file names which *end* in one or more exclamation marks and which also contain an "x" in the file name. If there is a second regex I can use for this then thank you.


x.*\!\.jpg
User avatar
Smite
Katamari Damacy Addict
 
Posts: 5318
Joined: Sat May 19, 2001 1:54 am
Location: Alberta, Canada

Registered Newsbin User since: 03/27/03

Postby yungblud » Sun Nov 09, 2003 10:46 am

Thank you kindly for the info. Just to recap, I am trying to identify files which are jpeg index files. Sorry to be fussy buta s I don't understand regex very well at all can I check two point with you.

(PART 1) Does this expression

\!.*\.jpg

refer to jpeg file names which have an exclamation mark in the middle? For example JOE!BROWN.JPG. I want a regex which does NOT refer to such file names.

As you may recall I want to refer to files which strictly START their name with an exclamation mark (or more than one) but NOT to those files which have exclamation marks in the middle of text. This means that the exclamation marks(s) would need to be followed by some text.

Files which have names of "!!!!!.jpg" are unlikely to be index files and I would like to NOT inlcude them in the regex. Is such a thing possible in a regex expression?

(PART 2) I also asked for an 'improved' regex to catch those file names which have an "x" character in the middle in addition to the file name starting with one or more exclamation marks.

I would probably use this regex rather than the regex above in PART 1 so perhaps the one that was given to me for this need replaces the requirement to modify what I have got above. I was given this:

\!.*x.*\.jpg

However I still do NOT want to include file names like !!!!.jpg. Can someone comment on whether the regex meets this requirement.

Thank you.
User avatar
yungblud
Seasoned User
Seasoned User
 
Posts: 168
Joined: Fri Sep 19, 2003 12:29 pm

Postby Smite » Sun Nov 09, 2003 10:04 pm

Sorry, no it will catch any filename with a ! in it, regardless of where it is.
If you want to only catch filenames that start with !, try:
^\!.*x.*\.jpg

as a filename reject filter. This won't work as a subject reject filter, since it's not the subject starting with a ! that we're looking for. Since !!!!.jpg starts with a ! though, it will still be caught.
User avatar
Smite
Katamari Damacy Addict
 
Posts: 5318
Joined: Sat May 19, 2001 1:54 am
Location: Alberta, Canada

Registered Newsbin User since: 03/27/03


Return to Regular Expressions

Who is online

Users browsing this forum: No registered users and 2 guests

cron