Wildcards question?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Wildcards question?

Post by alex.barylski »

When dealing with wildcards on a command line using ls or whatever, is it possible to using regex, extract the extension(s) of files that are currently being sought???

Is it safe to just use a simple substr() and extract everything after the first '.'???

Can regex be used to extract that string?

Cheers :)
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Is it safe to just use a simple substr() and extract everything after the first '.'???
you are right to question this because it isn't. try pathinfo.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

regex can perform it, yes.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

feyd wrote:regex can perform it, yes.
100% all the time?

Is something like this not possible using wildcards:

Code: Select all

a???_test{.bmp; .pdf}
as opposed to:

Code: Select all

a???_test.bmp
I've read up on using unix wildcards and it seems pretty flexible...which made me think impossible to parse using regex - I should say to always extract the extension(s) being searched...

I don't suppose you would care to show me the regex required for such a task - if indeed you can perform such an extraction... 8)

Cheers :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

A properly written regex should be able to pull the information. Some additional processing may be required, but that is beyond regex's control.
Post Reply