TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Lee Mac on August 04, 2010, 06:32:21 PM

Title: wcmatch mental block
Post 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.

Code: [Select]
"TEST1"   = T
"TEST123" = T
"TEST12A" = NIL

I have:

Code: [Select]
(wcmatch <string> "TEST[0-9]*")

However, this fails with the third of my examples  :|

Any help is, of course, appreciated.
Title: Re: wcmatch mental block
Post by: T.Willey on August 04, 2010, 06:36:59 PM
Command: (wcmatch "the12" "*[0-9]")
T

Command: (wcmatch "the133333333333332" "*[0-9]")
T

Command: (wcmatch "the" "*[0-9]")
nil

?
Title: Re: wcmatch mental block
Post by: ronjonp on August 04, 2010, 07:16:07 PM
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)
Title: Re: wcmatch mental block
Post by: CAB on August 04, 2010, 07:36:24 PM
Works for me :?

Command: (wcmatch "the12" "*#")
T

Command: (wcmatch "the2" "*#")
T

Command: (wcmatch "the2a" "*#")
nil
Title: Re: wcmatch mental block
Post by: CAB on August 04, 2010, 07:38:03 PM
Ron, I see, when you said it doesn't work you meant it returns nil. :-o
Title: Re: wcmatch mental block
Post by: VovKa on August 05, 2010, 02:49:50 AM
Lee, don't you want to right-trim the digits before using wcmatch?
Title: Re: wcmatch mental block
Post by: Lee Mac on August 05, 2010, 01:54:15 PM
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.

Code: [Select]
TEST123 = T
TESTING123 = nil
TEST123A = nil

So far:

Code: [Select]
(wcmatch "TESTING123" "*[0-9]") = T (wrong)

(wcmatch "TESTING123" "*#") = T (wrong)

Apologies if I wasn't clear  :oops:
Title: Re: wcmatch mental block
Post by: Lee Mac on August 05, 2010, 01:55:55 PM
VovKa's proposition:

Code: [Select]
(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...
Title: Re: wcmatch mental block
Post by: LE3 on August 05, 2010, 02:07:05 PM

Code: [Select]
(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:
Title: Re: wcmatch mental block
Post by: Lee Mac on August 05, 2010, 02:17:08 PM
I am looking for string such:

Code: [Select]
"TEST#########...###"
Title: Re: wcmatch mental block
Post by: LE3 on August 05, 2010, 02:31:33 PM
what do you think of something like this draft:
Code: [Select]
(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:

Code: [Select]
"TEST#########...###"
Title: Re: wcmatch mental block
Post by: Lee Mac on August 05, 2010, 02:37:09 PM
Not quite:

Code: [Select]
(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 :-)

Title: Re: wcmatch mental block
Post by: LE3 on August 05, 2010, 02:40:05 PM
i know... tried to play too :) - and no idea if can be done without using any combination :(

Not quite:

Code: [Select]
(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 :-)


Title: Re: wcmatch mental block
Post by: MP on August 05, 2010, 03:16:18 PM
Not sure I'm following but perhaps ...

Code: [Select]
(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.
Title: Re: wcmatch mental block
Post by: Lee Mac on August 05, 2010, 03:17:11 PM
Almost, but:

Code: [Select]
$ (haha "test42a42" '("test#*" "~*[~0-9]"))
T
Title: Re: wcmatch mental block
Post by: Lee Mac on August 05, 2010, 03:30:32 PM
Perhaps using Regular Expressions:

Code: [Select]
(
  (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

Code: [Select]
(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...
Title: Re: wcmatch mental block
Post by: MP on August 05, 2010, 03:54:52 PM
Easy to remedy: Just add another filter to the list: "~*#[~0-9]#*".

:)
Title: Re: wcmatch mental block
Post by: CAB on August 05, 2010, 04:26:01 PM
How about this?
Code: [Select]
(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
Title: Re: wcmatch mental block
Post by: CAB on August 05, 2010, 04:33:44 PM
Oops that one will not catch decimals but this should work.

Code: [Select]
(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
Title: Re: wcmatch mental block
Post by: ronjonp on August 05, 2010, 04:35:55 PM
Nice solution CAB  8-)
Title: Re: wcmatch mental block
Post by: Lee Mac on August 05, 2010, 04:38:54 PM
Nice solution Alan - kind of the reverse of VovKa's suggestion  8-)
Title: Re: wcmatch mental block
Post by: Lee Mac on August 05, 2010, 05:21:10 PM
Easy to remedy: Just add another filter to the list: "~*#[~0-9]#*".

:)

Is there a wcmatch wildcard for AND, like there is "," for OR ?
Title: Re: wcmatch mental block
Post by: CAB on August 05, 2010, 06:45:32 PM
What would be an example where AND would be used?
Title: Re: wcmatch mental block
Post by: Lee Mac on August 06, 2010, 02:14:35 PM
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.
Title: Re: wcmatch mental block
Post by: LE3 on August 08, 2010, 04:13:20 PM
Code: [Select]
(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:
Code: [Select]
(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]*" "*@*" "*.*"))))
Title: Re: wcmatch mental block
Post by: jbuzbee on August 13, 2010, 09:25:43 AM
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

!!!!!

Title: Re: wcmatch mental block
Post by: CAB on August 13, 2010, 09:28:20 AM
It's not new, just undocumented.  8-)
Title: Re: wcmatch mental block
Post by: jbuzbee on August 13, 2010, 09:40:55 AM
 :-D :-D :-D

Have a great weekend everone!
Title: Re: wcmatch mental block
Post by: Kerry on August 13, 2010, 03:57:12 PM
It's not new, just undocumented.  8-)


 :-)
Title: Re: wcmatch mental block
Post by: Lee Mac on August 14, 2010, 09:04:58 AM
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: