Better WCMATCH?

Discussion in 'AutoCAD' started by JeremyDunn, Oct 5, 2004.

  1. JeremyDunn

    JeremyDunn Guest

    AutoLISP of course does not have a full fledged regexp engine like PERL or VBSCRIPT but only has lowly WCMATCH which is not quite up to the task. Does anyone...

    1. Has anyone written a better WCMATCH for themself that they can share with us or

    2. Is there any way to access the VBSCRIPT regexp from within AutoLISP?
     
    JeremyDunn, Oct 5, 2004
    #1
  2. JeremyDunn

    Jeff Mishler Guest

    Not to sound dumb, but what is regexp?
     
    Jeff Mishler, Oct 5, 2004
    #2
  3. JeremyDunn

    JeremyDunn Guest

    Sorry, a "regexp" is a REGular EXPression and WCMATCH is a regular expression pattern matching function but not as sophisticated as in other programs.
     
    JeremyDunn, Oct 5, 2004
    #3
  4. Where is it that wcmatch falls short of your expectations?

    --
    Autodesk Discussion Group Facilitator



    VBSCRIPT but only has lowly WCMATCH which is not quite up to the task. Does
    anyone...
     
    Jason Piercey, Oct 5, 2004
    #4
  5. JeremyDunn

    JeremyDunn Guest

    Well, for one thing it doesn't handle maximum and minimum numbers of repetitions. You can't write something like

    "ab(xy 3 5)pq"

    to indicate you are matching from 3 to 5 copies of "xy".
     
    JeremyDunn, Oct 5, 2004
    #5
  6. JeremyDunn

    David Bethel Guest

    Something I do on daily basis.......

    -David
     
    David Bethel, Oct 5, 2004
    #6
  7. JeremyDunn

    MP Guest

    you should be able to set a reference to the vbscript.regexp interface via
    lisp and use that
    not sure if it should be:
    (setq regex
    (vla-getInterfaceObject
    (vlax-get-acad-object)
    "vbscript.regexp"
    )
    )

    or:
    (setq regex
    (vlax-create-object
    "vbscript.regexp"
    )
    )

    either way returns the following:
    #<VLA-OBJECT RegExp 18d01548>
    _$


    however when i try this
    (vlax-dump-object regex)
    i get this
    ; RegExp: nil
    ; error: bad argument type: fixnump: nil
    so i don't know whats wrong

    I don't know enough about reg exps to test the object but if I cant' even
    dump it's props somethings not right

    ;if you get it working
    ;don't forget
    (vlax-release-object regex)
    (setq regex nil)

    I found this searching my info files....haven't ever used it so don't know
    if it would work for you
    (usually *not recommended* to use acet-* functions)
    eg:
    (acet-str-find find string [ignoreCase [useRegExp]])

    Find substring in string.

    Arguments
    find: The substring to locate.
    string: The string to search.
    ignoreCase: If provided and non-nil, indicates that case
    insensitive
    comparisons should be performed.
    useRegExp: If provided and non-nil, indicates that regular
    expressions should be used for searching.

    This function uses the following definitions for regular
    expressions:

    . Matches any single character.
    * Postfix. Preceeding item 0 or more times.
    + Postfix. Preceeding item 1 or more times.
    ^ Matches empty string at beginning of text.
    $ Matches empty string at end of text.
    [chars] Matches any character in the given class. If the first
    character is ^, match any character not in the given class. A
    range
    of character may be specified by first-last, as in [A-Z] to
    specify
    upper case alphabetic characters.
    \( Mark the beginning of a subexpression.
    \) Mark the end of a subexpression.
    \digit Matches a repeat of the text matched earlier by the
    subexpression inside the nth opening parenthesis. Subexpressions
    may
    also be referenced in replace strings.


    Return Values
    The 1-based index if found, or nil if not found.

    good luck and let us know if anything worked
    hth
    Mark


    VBSCRIPT but only has lowly WCMATCH which is not quite up to the task. Does
    anyone...
     
    MP, Oct 6, 2004
    #7
  8. ;; REGEXP.LSP
    ;; Copyright (c) 2004, Tony Tanzillo
    ;;
    ;; Sample showing how to use RegExp from Visual LISP

    (defun RegExpTest ( / RegExp cnt match result i)

    (setq RegExp (vlax-create-object "VBScript.RegExp"))

    (vlax-put-property RegExp 'Pattern "is.")

    (vlax-put-property RegExp 'Global :vlax-true)

    (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 ;;;;;;;;;;;;;;



    is not quite up to the task. Does anyone...
     
    Tony Tanzillo, Oct 6, 2004
    #8
  9. JeremyDunn

    JeremyD Guest

    Thank you so much, this will be of enormous help. Too bad the AutoLISP help file for WCMATCH doesn't have this useful piece of information in it.
     
    JeremyD, Oct 6, 2004
    #9
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.