News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.

Post Reply  Post Thread 
match one of three possible substrings?
Author Message
Junior Member

Posts: 35
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #1
RE: match one of three possible substrings?

mikshaw Wrote:

if string.find(allfiles[i],"%.png$") or string.find(allfiles[i],"%.jpg$") or string.find(allfiles[i],"%.gif$") then

The trick is to use regular expressions. Unfortunately, lua doesn't implement the PCRE ones, only a simplified version of it. You can find information about this in this Patterns Tutorial or in this lua cheat sheet (pdf).

You can try something like this:

extension = string.find(allfiles[i],"(%.[pjg][npi][gf]$)")
if extension = ".png" or extension = ".jpg" or extension = ".gif" then

The first line will capture the extension part. [pjg] means a letter that matches any on of p, j, or g.

You can also check out string.gmatch and string.match if you want to run your search on the full list rather than on element x of the list.

This post was last modified: 06-10-2007 10:42 PM by widged.

06-10-2007 10:41 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Messages In This Thread
RE: match one of three possible substrings? - widged - 06-10-2007 10:41 PM

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: