That's awesome stuff Joe! I didn't know there was such a thing as "VBScript.RegExp". That's pretty cool. This is available to VBA?
Hi Mark,
I thought it was pretty interesting too. Also curious, the topic I referred
to seems to be the only mention of regular expressions within vlisp in the entire
Autodesk customization NG.
Here's a link to that topic
http://tinyurl.com/f9z4t and Tony's example code
below for anyone interested.
Regarding VBA, sorry, I don't know about that.
There's three methods available.
;; RegExp Methods: Execute, Replace and Test
;;
;; Execute
;; Execute the regular expression search.
;;
;; Replace
;; Replace Pattern in string with a new string.
;;
;; Test
;; Returns boolean if search Pattern occurs in string.
Obviously Tony's code is an example of the Execute method. Which might have been
called the search method. That's how I think of it anyway.
His example was all I had to go on while trying to figure out how to use the
Replace method. It looks obvious in hindsight, but I'm sure you know how frustrating
trial and error can be with this stuff.
Sometime soon I'll post my version of Tony's code named RegExp:Search. I added
some error handling like the vl-catch-all-apply in RegExp:Replace. The main reason
for that is an invalid pattern will toss an "Exception occurred" error. And I still
have a lot to learn about the Pattern argument.
I also have a RegExp:Test function which I'll post.
I hope anyone here who is familiar with regular expressions might share what they
know. I'm fumbling around in the dark. What little I've learned comes from searching
the web. What I found does not apply specifically to their use within vlisp.
Maybe this deserves a separate topic? If you think so, please start one.
Regards
;;;;;;;;;;; REGEXP.LSP ;;;;;;;;;;;;;;
;; REGEXP.LSP
;; Copyright (c) 2004, Tony Tanzillo
;; Sample showing how to use RegExp from Visual LISP
;; Comments added JB.
;; Returns:
;; Matches found: 4
;; Match[0]: IS1
;; Match[1]: is2
;; Match[2]: IS3
;; Match[3]: is40
(defun RegExpTest ( / RegExp cnt match result i)
(setq RegExp (vlax-create-object "VBScript.RegExp"))
;search pattern
(vlax-put-property RegExp 'Pattern "is.")
;search for all occurances or only first match
(vlax-put-property RegExp 'Global :vlax-true)
;search is not case sensitive
(vlax-put-property RegExp 'IgnoreCase :vlax-true)
(setq result
(vlax-invoke-method RegExp 'Execute "IS1 is2 IS3 is4")
)
(princ
(strcat
"\nMatches found: "
(itoa (setq cnt (vlax-get-property Result 'Count)))
)
)
(setq i 0)
(repeat cnt
(setq match (vlax-get-property Result 'Item i))
(princ
(strcat
"\nMatch[" (itoa i) "]: "
(vlax-get-property Match 'Value)
)
)
(setq i (1+ i))
)
(vlax-release-object result)
(vlax-release-object RegExp)
)
;;;;;;;;;;; REGEXP.LSP ;;;;;;;;;;;;;;