gazillabyte
asked on
Using the posix fnmatch to compare to an empty string
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 ;-)