Author Topic: wcmatch mental block  (Read 5997 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