Solved

Using the posix fnmatch to compare to an empty string

Posted on 2013-01-21
2
328 Views
Last Modified: 2013-11-13
I have a lot of code that uses the fnmatch C function to match strings against patterns.

From time to time I want to match against empty strings, but the wildcard * relates to one or more characters, not zero characters.

I was sure you could achieve a pattern to match all blank strings with

!(?*)

meaning any string that is not one character or more in length, but this does not match.

What is the "right" way to get a match from:

fnmatch(..., "", 0)

where ... is the pattern?
0
Comment
Question by:gazillabyte
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 150 total points
ID: 38803689
fnmatch("", "", 0)
0
 

Author Comment

by:gazillabyte
ID: 38804077
Cheers.

I had a wrapper around fnmatch which checked the length of the pattern and the string and returned false if they were both empty. It must have seemed like a good idea at the time ;-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
A short article about problems I had with the new location API and permissions in Marshmallow

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question