473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Matching a filename

I wanna match the incorrect filename with the next regular expression
but it doesn´t work. Why? I don´t know.

if (ereg("[^A-Za-z0-9\.]+", $str))
return false;
else
return true;

I wanna allow only letters (A-Za-z) and numbers (0-9) and of course a
dot for the extension.

Have anybody any suggestion or idea? Any idea would be appreciated!!
Fran García
Jul 17 '05 #1
2 1224
On 2005-02-25, Fran Garcia <fg*****@ua.es> wrote:
I wanna match the incorrect filename with the next regular expression
but it doesn´t work. Why? I don´t know.

if (ereg("[^A-Za-z0-9\.]+", $str))
return false;
else
return true;


return preg_match("#^[A-Za-z0-9\.]+$#", $str)

but what about $string = "C:\\My Documents" ?


--
Met vriendelijke groeten,
Tim Van Wassenhove <http://www.timvw.info>
Jul 17 '05 #2
"Tim Van Wassenhove" <ti***@users.sourceforge.net> wrote in message
news:38*************@individual.net...
On 2005-02-25, Fran Garcia <fg*****@ua.es> wrote:
I wanna match the incorrect filename with the next regular expression
but it doesn´t work. Why? I don´t know.

if (ereg("[^A-Za-z0-9\.]+", $str))
return false;
else
return true;


return preg_match("#^[A-Za-z0-9\.]+$#", $str)

but what about $string = "C:\\My Documents" ?


preg_match('/^[\w\.]+$/', $str) is more compact; covers the underscore as
well.
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Martin Lucas-Smith | last post by:
Is there some way of using ereg to detect when certain filename extensions are supplied and to return false if so, WITHOUT using the ! operator before ereg () ? I have an API that allows as an...
7
by: Matt L. | last post by:
In summary, I don't know how/why the following code works and would like to know. I'm trying to match the first 3 characters of a variable (filename). The code below crudely works, but only if I...
9
by: Martijn | last post by:
Hi, Which is the prevalent way of matching a filename to a mask in runtime? The best I can think of, is sscanf. Thanks for the help! <OT> It's for the Windows platform, so any functions...
2
by: Brian Parker | last post by:
I have an ArrayList ( strings ) of filenames like such: fred.out inctructions.txt luncheon01.jpg luncheon02.jpg luncheon05.jpg luncheon11.jpg HeebieJeebie.cs ...etc..
8
by: EP | last post by:
Hi, I'm a bit green in this area and wonder to what extent there may be some existing Python tools (or if I have to scratch my head real hard for an appropriate algorithm... ) I'd hate to build...
5
by: Mike C# | last post by:
Hi all, quick question. Is there a Windows function I can call to compare a single string like "HELLO.TXT" to a Windows filename/path pattern (possibly with wildcards) like "H?LL?.*" ? Basically...
1
by: Peter v.d. Berger | last post by:
Hello, I'm working on a script that can place results of soccergames from different seasons in a row, to see the history of the game. I've gattered a lot of scores from different websites on a...
97
by: luap | last post by:
Hello good friends, please i need your help and advice on how i should best programme the problem, if possible a different option to solve it is welcomed. The problem a matching problem, how to...
11
by: tech | last post by:
Hi, I need a function to specify a match pattern including using wildcard characters as below to find chars in a std::string. The match pattern can contain the wildcard characters "*" and "?",...
0
by: grego9 | last post by:
I have a bit of visual basic code in an excel spreadsheet that I need some help with. I am attempting to search a file called TO Cancellations2.xls for counterparty names and for each counterparty...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.