Author Topic: Wcmatch question  (Read 2523 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1447
  • Marco
Wcmatch question
« on: March 31, 2015, 09:34:44 AM »
I need to wcmatch a string which contains "- pippo", why this filter "*- pippo* is not enough, but I have to use this "*-?pippo*" ?

Code: [Select]
Comando: (wcmatch "ciao come stai - pippo" "*- pippo*")
T
Comando: (wcmatch "ciao come stai -  pippo" "*- pippo*")
T
Comando: (wcmatch "ciao come stai -        pippo" "*- pippo*")
T
Comando: (wcmatch "ciao come stai -        pippo" "*-?pippo*")
nil
Comando: (wcmatch "ciao come stai - pippo" "*-?pippo*")
T
Comando: (wcmatch "ciao come stai - pippo " "*-?pippo*")
T
Comando: (wcmatch "ciao come stai - pippo " "*- pippo*")
T

ronjonp

  • Needs a day job
  • Posts: 7524
Re: Wcmatch question
« Reply #1 on: March 31, 2015, 10:10:12 AM »
? matches any single character. Your example has multiple spaces. I would use:
(wcmatch "ciao come stai -        pippo" "*-*pippo*")

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1447
  • Marco
Re: Wcmatch question
« Reply #2 on: March 31, 2015, 10:23:00 AM »
I need to wcmatch a string which only contains "- pippo" not "-  pippo" (2 spaces) or "-   pippo" (3 sp.) and so on, only exactly "- pippo".

Jeff_M

  • King Gator
  • Posts: 4078
  • C3D user & customizer
Re: Wcmatch question
« Reply #3 on: March 31, 2015, 10:24:47 AM »
Ron, I think his query has to do with one of these returning T when one would think they should both return nil:

Comando: (wcmatch "ciao come stai -        pippo" "*- pippo*")
T
Comando: (wcmatch "ciao come stai -        pippo" "*-?pippo*")
nil

I don't see anything in the documentation that would suggest a single space would equal any number of spaces.

Jeff_M

  • King Gator
  • Posts: 4078
  • C3D user & customizer
Re: Wcmatch question
« Reply #4 on: March 31, 2015, 10:29:13 AM »
Looks like using the Escape character ` works:
Command: (wcmatch "ciao come stai - pippo" "*-` pippo*")
T
Command: (wcmatch "ciao come stai -        pippo" "*-` pippo*")
nil

ronjonp

  • Needs a day job
  • Posts: 7524
Re: Wcmatch question
« Reply #5 on: March 31, 2015, 10:34:13 AM »
Ahhh .. I see .. (wcmatch "ciao come stai -        pippo" "*- pippo*") T <- that is strange.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1447
  • Marco
Re: Wcmatch question
« Reply #6 on: March 31, 2015, 10:36:17 AM »
Ron, I think his query has to do with one of these returning T when one would think they should both return nil:

Comando: (wcmatch "ciao come stai -        pippo" "*- pippo*")
T
Comando: (wcmatch "ciao come stai -        pippo" "*-?pippo*")
nil

I don't see anything in the documentation that would suggest a single space would equal any number of spaces.
Yes, just a curiosity on the functioning of wcmatch.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Wcmatch question
« Reply #7 on: March 31, 2015, 10:46:43 AM »
Excerpt from the help:

Note: Because additional wild-card characters might be added in future releases of AutoLISP, it is a good idea to escape all non-alphanumeric characters in your pattern to ensure upward compatibility.

Also, all characters enclosed in brackets ([ . . . ]) are read literally, so there is no need to escape them.


Accordingly this will work (and is more eye friendly to me) as well as the "*-` pippo*" variant:

Code: [Select]
(progn

    (setq tests
       '(
            "ciao come stai - pippo"
            "ciao come stai -  pippo"
            "ciao come stai -        pippo"
            "ciao come stai - pippo"
            "ciao come stai - pippo "
        )
    )
   
    (setq pattern "*-[ ]pippo*")

    (foreach test tests   
        (princ
            (strcat
                "\n"
                (vl-prin1-to-string test)
                ": "
                (if (wcmatch test pattern) "T" "nil")
            )
        )
    )
   
    (princ)

)

>>

"ciao come stai - pippo": T
"ciao come stai -  pippo": nil
"ciao come stai -        pippo": nil
"ciao come stai - pippo": T
"ciao come stai - pippo ": T

Cheers/Ciao.
Engineering Technologist CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com http://cadanalyst.slack.com http://linkedin.com/in/cadanalyst


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Wcmatch question
« Reply #9 on: March 31, 2015, 10:59:50 AM »
:)
Engineering Technologist CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com http://cadanalyst.slack.com http://linkedin.com/in/cadanalyst