Author Topic: wcmatch mental block  (Read 5998 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
wcmatch mental block
« 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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: wcmatch mental block
« Reply #1 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

?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: wcmatch mental block
« Reply #2 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)
« Last Edit: August 04, 2010, 09:26:45 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: wcmatch mental block
« Reply #3 on: August 04, 2010, 07:36:24 PM »
Works for me :?

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

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

Command: (wcmatch "the2a" "*#")
nil
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: wcmatch mental block
« Reply #4 on: August 04, 2010, 07:38:03 PM »
Ron, I see, when you said it doesn't work you meant it returns nil. :-o
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: wcmatch mental block
« Reply #5 on: August 05, 2010, 02:49:50 AM »
Lee, don't you want to right-trim the digits before using wcmatch?

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: wcmatch mental block
« Reply #6 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:

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: wcmatch mental block
« Reply #7 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...

LE3

  • Guest
Re: wcmatch mental block
« Reply #8 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:

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: wcmatch mental block
« Reply #9 on: August 05, 2010, 02:17:08 PM »
I am looking for string such:

Code: [Select]
"TEST#########...###"

LE3

  • Guest
Re: wcmatch mental block
« Reply #10 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#########...###"

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: wcmatch mental block
« Reply #11 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 :-)


LE3

  • Guest
Re: wcmatch mental block
« Reply #12 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 :-)



MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: wcmatch mental block
« Reply #13 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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: wcmatch mental block
« Reply #14 on: August 05, 2010, 03:17:11 PM »
Almost, but:

Code: [Select]
$ (haha "test42a42" '("test#*" "~*[~0-9]"))
T

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: wcmatch mental block
« Reply #15 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...

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: wcmatch mental block
« Reply #16 on: August 05, 2010, 03:54:52 PM »
Easy to remedy: Just add another filter to the list: "~*#[~0-9]#*".

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: wcmatch mental block
« Reply #17 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
« Last Edit: August 05, 2010, 04:29:04 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: wcmatch mental block
« Reply #18 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
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: wcmatch mental block
« Reply #19 on: August 05, 2010, 04:35:55 PM »
Nice solution CAB  8-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: wcmatch mental block
« Reply #20 on: August 05, 2010, 04:38:54 PM »
Nice solution Alan - kind of the reverse of VovKa's suggestion  8-)

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: wcmatch mental block
« Reply #21 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 ?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: wcmatch mental block
« Reply #22 on: August 05, 2010, 06:45:32 PM »
What would be an example where AND would be used?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: wcmatch mental block
« Reply #23 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.

LE3

  • Guest
Re: wcmatch mental block
« Reply #24 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]*" "*@*" "*.*"))))
« Last Edit: August 08, 2010, 10:57:17 PM by LE »

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: wcmatch mental block
« Reply #25 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

!!!!!

James Buzbee
Windows 8

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: wcmatch mental block
« Reply #26 on: August 13, 2010, 09:28:20 AM »
It's not new, just undocumented.  8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: wcmatch mental block
« Reply #27 on: August 13, 2010, 09:40:55 AM »
 :-D :-D :-D

Have a great weekend everone!
James Buzbee
Windows 8

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: wcmatch mental block
« Reply #28 on: August 13, 2010, 03:57:12 PM »
It's not new, just undocumented.  8-)


 :-)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: wcmatch mental block
« Reply #29 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: