Author Topic: Wcmatch patterns  (Read 2562 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1447
  • Marco
Wcmatch patterns
« on: December 21, 2017, 03:33:38 PM »

Maybe it is a stupid question:
Code: [Select]
(wcmatch  "*D4"   "[~*]*") => nil
(wcmatch  "X_Foo" "~X_*" ) => nil

How combine "[~*]*" and "~X_*" to get nil? 
Code: [Select]
(wcmatch  "*D4"   "[~*]*,~X_*") => T
(wcmatch  "X_Foo" "[~*]*,~X_*") => T

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Wcmatch patterns
« Reply #1 on: December 21, 2017, 03:48:20 PM »
Should do it:

Code: [Select]
(defun _WcmatchAll ( text patterns )
    (vl-every
        (function (lambda (p) (wcmatch text p)))
        patterns
    )
)

(_WcmatchAll "*D4" '("[~*]*" "~X_*")) >> nil
(_WcmatchAll "X_Foo" '("[~*]*" "~X_*")) >> nil

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

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Wcmatch patterns
« Reply #2 on: December 21, 2017, 03:53:26 PM »
This works for the two provided examples:
Code: [Select]
(wcmatch "*D4"   "[~*][~_]*")
(wcmatch "X_Foo" "[~*][~_]*")

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1447
  • Marco
Re: Wcmatch patterns
« Reply #3 on: December 21, 2017, 04:03:58 PM »
Thanks, tomorrow morning I will try. Notte...  8)

Lee Mac

  • Seagull
  • Posts: 12892
  • London, England
Re: Wcmatch patterns
« Reply #4 on: December 21, 2017, 05:40:12 PM »
Alternatively:
Code: [Select]
(not (wcmatch "*D4"   "`**,X_*")) -> nil
(not (wcmatch "X_Foo" "`**,X_*")) -> nil

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Wcmatch patterns
« Reply #5 on: December 21, 2017, 07:05:13 PM »
Based on observations (which means I'm not sure about this) :

Code: [Select]
_$ (wcmatch "*D4" "[~`**][~X_*]")
nil
_$ (wcmatch "X_Foo" "[~`**][~X_*]")
nil
_$ (wcmatch "D4" "[~`**][~X_*]")
T
_$ (wcmatch "X_test" "[~`**][~X_*]")
nil
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Wcmatch patterns
« Reply #6 on: December 21, 2017, 09:56:44 PM »
Not trying to hijack the thread, but I have so many questions after trying an alternative approach:

Does anyone already came up with a handy subfoo like this? :
Code: [Select]
; _$ (rgxtest "d" "([A-Z]|[a-c]|[1-4])") -> :vlax-false
; _$ (rgxtest "hjk" "[a-c]") -> :vlax-false
; _$ (rgxtest "hjck" "[a-c]") -> :vlax-true
(defun rgxtest ( str rgxpat / _trapeval rgx r )
 
  (setq _trapeval
    (lambda (a b / c)
      (setq c (vl-catch-all-apply (function (lambda (b) ((eval a) b))) (list b)))
      (cond ( (vl-catch-all-error-p c) (prompt (strcat "\n" (vl-catch-all-error-message c))) ) (c))
    )
  )
 
  (cond
    ( (not (setq rgx (_trapeval 'vlax-get-or-create-object "vbscript.regexp"))) )
    (
      (setq r
        (_trapeval
          (lambda (x)
            (vlax-put-property rgx 'global actrue)
            (vlax-put-property rgx 'multiline actrue)
            (vlax-put-property rgx 'pattern rgxpat)
            (vlax-invoke-method rgx 'Test str)
          )
          nil
        )
      )
    )
  ); cond
  (_trapeval 'vlax-release-object rgx) r
); defun rgxtest

What should be the correct regex pattern to match Marc's criteria? I tried:
Code: [Select]
_$ (rgxtest "preffix-x_-suffix" "([*])|(?:[Xx][_])")
:vlax-true

But thats not correct, due the preffix it should return :vlax-false.
What stands the wcmatch "*" (asteriks) substitute thats being used in regex "multiple times any characters"?
say implement this wcmatch filter as regex pattern: (wcmatch str "*H*")
Literal asteriks such as in wcmatch "`*" in regex is "[the_asteriks_symbol_here]" - right?
 :thinking:
« Last Edit: December 21, 2017, 10:01:21 PM by Grrr1337 »
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1447
  • Marco
Re: Wcmatch patterns
« Reply #7 on: December 22, 2017, 03:54:13 AM »
Should do it:

Code: [Select]
(defun _WcmatchAll ( text patterns )
    (vl-every
        (function (lambda (p) (wcmatch text p)))
        patterns
    )
)

(_WcmatchAll "*D4" '("[~*]*" "~X_*")) >> nil
(_WcmatchAll "X_Foo" '("[~*]*" "~X_*")) >> nil

I think this is the only solution to have the same behaviour:

"[~*]*" => no strings starting with    *       (i.e. anonimous blocks) and
"~X_*"  => no strings starting with   X_

Also Lee solution seems OK but I need only "positive" test to add other strings.

Thanks.  :-)

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Wcmatch patterns
« Reply #8 on: December 22, 2017, 07:39:04 AM »
...and I've ended up with some interesting (for me) result, playing with this regex route:
Code - Auto/Visual Lisp: [Select]
  1. (defun rgxexec ( str rgxpat / _trapeval rgx r )
  2.  
  3.   (setq _trapeval
  4.     (lambda (a b / c)
  5.       (setq c (vl-catch-all-apply (function (lambda (b) ((eval a) b))) (list b)))
  6.     )
  7.   )
  8.  
  9.   (cond
  10.     ( (not (setq rgx (_trapeval 'vlax-get-or-create-object "vbscript.regexp"))) )
  11.     (
  12.       (setq r
  13.         (_trapeval
  14.           (lambda (x / MathColl2 L)
  15.             (vlax-put-property rgx 'global actrue)
  16.             (vlax-put-property rgx 'multiline actrue)
  17.             (vlax-put-property rgx 'pattern rgxpat)
  18.             (setq MathColl2 (vlax-invoke-method rgx 'Execute str))
  19.             (vlax-for o MathColl2 (setq L (cons (vlax-get-property o 'Value) L)))
  20.             (reverse L)
  21.           )
  22.           nil
  23.         )
  24.       )
  25.     )
  26.   ); cond
  27.   (_trapeval 'vlax-release-object rgx) r
  28. ); defun rgxexec

Attempting to obtain all stuff that wcmatch to "`*?" or "[Xx]_?" by using the " " (white space character) as delimiter:
Code - Auto/Visual Lisp: [Select]
  1.  _$ (rgxexec "*d4 x_ref bla *pat X_Abc end" "[*][\\S]|[\\s][*][\\S]|[\\s][Xx][_][\\S]") -> ("*d" " x_r" " *p" " X_A")

However obtaining "`**" or "[Xx]_*" patterns using " " as delimeter with regex seems impossible - thats my impression for now.  :rolleyes2:
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Wcmatch patterns
« Reply #9 on: December 22, 2017, 09:51:01 AM »
@Grrr1337:
Maybe you are looking for this:
Code: [Select]
(rgxexec "*d4 x_ref bla *pat X_Abc end" "[*]\\S*|[Xx]_\\S*") =>
("*d4" "x_ref" "*pat" "X_Abc")

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Wcmatch patterns
« Reply #10 on: December 22, 2017, 10:22:54 AM »
@Grrr1337:
Maybe you are looking for this:
Code: [Select]
(rgxexec "*d4 x_ref bla *pat X_Abc end" "[*]\\S*|[Xx]_\\S*") =>
("*d4" "x_ref" "*pat" "X_Abc")

Yes - I was trying to do exactly this, due getting started some regex practice.
Thank you, Roy!  :-)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg