TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Lee Mac on August 04, 2010, 06:32:21 PM
-
How can I ensure using wcmatch that a string ends with an indefinite length of numerical characters?
i.e.
"TEST1" = T
"TEST123" = T
"TEST12A" = NIL
I have:
(wcmatch <string> "TEST[0-9]*")
However, this fails with the third of my examples :|
Any help is, of course, appreciated.
-
Command: (wcmatch "the12" "*[0-9]")
T
Command: (wcmatch "the133333333333332" "*[0-9]")
T
Command: (wcmatch "the" "*[0-9]")
nil
?
-
I'd think that if it ended with numerical characters that you could not have an asterisk at the end?
(wcmatch "TEST12A" "*#*") works returns T
(wcmatch "TEST12A" "*#") does not work returns nil (as it should)
Maybe I'm missing the point :-D (it's been known to happen)
-
Works for me :?
Command: (wcmatch "the12" "*#")
T
Command: (wcmatch "the2" "*#")
T
Command: (wcmatch "the2a" "*#")
nil
-
Ron, I see, when you said it doesn't work you meant it returns nil. :-o
-
Lee, don't you want to right-trim the digits before using wcmatch?
-
Thanks guys, bit late getting back to you, but I have work now...
Lee, don't you want to right-trim the digits before using wcmatch?
That perhaps may be a solution - let me clarify for you all a bit:
I have a know prefix, say, 'TEST', and want wcmatch to return true if the string begins with 'TEST' and this is following by an indefinite list of numbers, i.e.
TEST123 = T
TESTING123 = nil
TEST123A = nil
So far:
(wcmatch "TESTING123" "*[0-9]") = T (wrong)
(wcmatch "TESTING123" "*#") = T (wrong)
Apologies if I wasn't clear :oops:
-
VovKa's proposition:
(eq (vl-string-right-trim "0123456789" <string>) "TEST")
works, but I am curious to see if this could be accomplished using wcmatch as I am not too practised in the art of wildcards...
-
(wcmatch "TESTING123" "*[0-9]") = T (wrong)
(wcmatch "TESTING123" "*#") = T (wrong)
Apologies if I wasn't clear :oops:
Clear as mud :)
Both of your strings above have the prefix of "TEST" and ends with a numeric value
_$ (wcmatch "TESTING123" "TEST*#") ;; start with the prefix and end with a numeric value
T
_$ (wcmatch "INGTEST123" "TEST*#")
nil
(wcmatch "TEST" "TEST*#") ;; start with the prefix but no numeric at the end...
nil
:roll:
-
I am looking for string such:
"TEST#########...###"
-
what do you think of something like this draft:
(defun prefixNumeric (string prefix)
(and (eq prefix (substr string 1 (strlen prefix)))
(wcmatch (substr string (+ (strlen prefix) 1)) "#*")
(wcmatch string "*#")))
(prefixNumeric "TESTING123" "TEST") ;; nil
(prefixNumeric "TEST123" "TEST") ;; t
(prefixNumeric "12333TEST123" "TEST") ;; nil
(prefixNumeric "TEST123dsadsadsa" "TEST") ;; nil
I am looking for string such:
"TEST#########...###"
-
Not quite:
(prefixnumeric "test123A123" "test")
T
But I have shown it can be done using VovKa's suggestion - just I wondered if there was a single wcmatch string to do it is all :-)
-
i know... tried to play too :) - and no idea if can be done without using any combination :(
Not quite:
(prefixnumeric "test123A123" "test")
T
But I have shown it can be done using VovKa's suggestion - just I wondered if there was a single wcmatch string to do it is all :-)
-
Not sure I'm following but perhaps ...
(defun haha ( text patterns )
(vl-every
'(lambda ( pattern ) (wcmatch text pattern))
patterns
)
)
(setq patterns '("test#*" "~*[~0-9]"))
(haha "test42" patterns) => T
(haha "test42a" patterns) => nil
(haha "test424242" patterns) => T
(haha "test424242a" patterns) => nil
As written is case sensitive which may or may not serve the OP's purposes.
-
Almost, but:
$ (haha "test42a42" '("test#*" "~*[~0-9]"))
T
-
Perhaps using Regular Expressions:
(
(lambda ( string pattern / rx result )
(setq rx (vlax-create-object "VBScript.RegExp"))
(setq result (LM:RegExExecute rx pattern string))
(vlax-release-object rx)
(and result)
)
"TEST4a4" "^TEST[0-9]*$"
)
==> nil
(defun LM:RegExExecute ( reg pat str / l )
;; © Lee Mac 2010
(mapcar
'(lambda ( prop value ) (vlax-put-property reg prop value))
'(pattern global ignorecase) (list pat actrue acfalse)
)
(vlax-for x (vlax-invoke reg 'execute str)
(setq l (cons (list (vlax-get x 'value) (vlax-get x 'firstindex)) l))
)
l
)
Not sure if the pattern is verbose however, as I haven't played around with RegEx enough...
-
Easy to remedy: Just add another filter to the list: "~*#[~0-9]#*".
:)
-
How about this?
(defun wcsuffix (str pre / )
(and
(wcmatch str "TEST*#")
(distof (substr str (1+(strlen pre)))2)
)
)
Command: (wcsuffix "TEST123" "TEST")
T
Command: (wcsuffix "TEST123a" "TEST")
nil
Command: (wcsuffix "TEST123a4" "TEST")
nil
-
Oops that one will not catch decimals but this should work.
(defun wcsuffix (str pre / tmp)
(and
(wcmatch str "TEST*#")
(setq tmp (substr str (1+(strlen pre))))
(= tmp (itoa(atoi tmp)))
)
)
Command: (wcsuffix "TEST123a4" "TEST")
nil
Command: (wcsuffix "TEST123" "TEST")
T
Command: (wcsuffix "TEST12.3" "TEST")
nil
-
Nice solution CAB 8-)
-
Nice solution Alan - kind of the reverse of VovKa's suggestion 8-)
-
Easy to remedy: Just add another filter to the list: "~*#[~0-9]#*".
:)
Is there a wcmatch wildcard for AND, like there is "," for OR ?
-
What would be an example where AND would be used?
-
What would be an example where AND would be used?
In place of MP's earlier suggestion, where he is using vl-every to make sure each pattern holds True.
-
(defun strPrefixIntNumSuffix (string prefix)
(and (wcmatch string (strcat prefix "*[0-9]*"))
(not (wcmatch string (strcat prefix "*[a-z]*")))
(not (wcmatch string (strcat prefix "*[A-Z]*")))
(not (wcmatch string (strcat prefix "*@*")))
(not (wcmatch string (strcat prefix "*.*")))))
(strPrefixIntNumSuffix "test_#!@$%^&*()_-+={}[]|\;'\":,<.>?/`~" "test");;nil
(strPrefixIntNumSuffix "test9999" "test");;T
(strPrefixIntNumSuffix "test9999000000000000000e" "test");;nil
(strPrefixIntNumSuffix "test999900000.000000000" "test");;nil
(strPrefixIntNumSuffix "testpppp9999____oooo00000.000000000" "test");;nil
(strPrefixIntNumSuffix "test999900009-00000000000)))" "test");;nil
(strPrefixIntNumSuffix "99999test99990000900000000000)))" "test") ;;nil
(strPrefixIntNumSuffix "9999999990000900000000000" "test") ;;nil
edit:added more tests
or this short version:
(defun strNum (string prefix)
(and (wcmatch string (strcat prefix "*[0-9]*"))
(vl-every (function (lambda (pattern) (not (wcmatch string (strcat prefix pattern)))))
(list "*[a-z]*" "*[A-Z]*" "*@*" "*.*"))))
-
When I read the title of this thread: "Wcmatch mental block" I thought: I've never heard of a Mental Block. Is this some new kind of dynamic block for 2011? (I'm still on 2009) What would a mental block be able to do over a regular block or a dynamic block? AI?
that would be scary.
that's how messed up my brain is right now. :lol:
TGIF
!!!!!
-
It's not new, just undocumented. 8-)
-
:-D :-D :-D
Have a great weekend everone!
-
It's not new, just undocumented. 8-)
:-)
-
When I read the title of this thread: "Wcmatch mental block" I thought: I've never heard of a Mental Block. Is this some new kind of dynamic block for 2011? (I'm still on 2009) What would a mental block be able to do over a regular block or a dynamic block? AI?
It's not new, just undocumented. 8-)
lol :lol: