Wildcard In String

David Bethel

Usenet Archive
Joined
Nov 22, 2001
Messages
135
Reaction score
0
Anyone know of a simple wcmatch test to see if a string contains a wildcard character as in a block name pattern search?

So far I have:

(while (or (not bn)
(not (or (snvalid bn)
(wcmatch bn [ "#" "@" "." "*" "?" "~" "[" ]))))
(setq bn (getstring "\nBlock Name Pattern: ")))

-David
 
Hi David,

Didn't test this much, but how about....

; function to determine if a string
; contains any wildcard characters.
(defun wcmatchChr (string)
(wcmatch string "*[#@.*?~]*")
)

(wcmatchChr "a#bc") -> T
(wcmatchChr "a*bc") -> T
(wcmatchChr "a?bc") -> T
(wcmatchChr "abc") -> nil

?
 
Thanks

I did have to add a back quote for commas ????

(wcmatch string "*[#@.`,*?~]*")

-David
 
Shouldn't have to escape the comma...

<snip>
All characters enclosed in brackets ([ . . . ]) are read literally, so there is no need to escape them, with the following exceptions: the tilde character (~) ........
<snip>
 
oops! misplaced comma..... You are correct

(setq string "a,b")
"a,b"

(wcmatch string "*[#@.*?~,]*")
nil

(wcmatch string "*[#@.*?~`,]*")
T

Jason Piercey said:
Hmmm.... 2002

(setq string "a,b")
"a,b"

(wcmatch string "*[#@.*?~],*")
T

David Bethel said:
Didn't work that way

R12 -David
 
Here's an old one...
;;--------------------------------------------------
;; Function to turn a string into a literal string:
;;
(defun @literal (str / new ch i n)
(setq i 1
n (strlen str)
new ""
)
(while (<= i n)
(setq new (strcat new "`" (substr str i 1))
i (1+ i)
)
)
new
)
 
I have a program where the user enters his own custom description prefixes and suffixes that can contain any characters, so you have to read them literally...

Command: (setq str "320.01.#" prefix "320.01" suffix ".#") ".#"
Command: (wcmatch str (strcat prefix "*" suffix))
nil
Command: (wcmatch str (strcat (@literal prefix) "*" (@literal suffix)))
T

So you say "why don't you just test for equality?"
Because there might be other characters in the string between the prefix and suffix that are permitted...
Command: (setq str "320.01A.#")
"320.01A.#"
Command: (wcmatch str (strcat (@literal prefix) "*" (@literal suffix)))
T
 
Back
Top