wcmatch - AutoCAD AutoLISP function
wcmatch is an AutoLISP function that performs a wild-card pattern match on a string.
Syntax: (wcmatch string pattern)
Where the arguments are string an pattern:
A string to be compared. The comparison is case-sensitive, so uppercase and lowercase characters must match.
A string containing the pattern to match against string. The pattern can contain the wild-card pattern-matching characters shown in the table Wild-card characters. You can use commas in a pattern to enter more than one pattern condition. Only the first 500 characters (approximately) of the string and pattern are compared; anything beyond that is ignored.
Both arguments can be either a quoted string or a string variable. It is valid to use variables and values returned from AutoLISP functions for string and pattern values.
If string and pattern match, wcmatch returns T; otherwise, wcmatch returns nil.
|# (pound)||Matches any single numeric digit.|
|@ (at)||Matches any single alphabetic character.|
|. (period)||Matches any single nonalphanumeric character.|
|* (asterisk)||Matches any character sequence, including an empty one, and it can be used anywhere in the search pattern: at the beginning, middle, or end.|
|? (question mark)||Matches any single character.|
|~ (tilde)||If it is the first character in the pattern, it matches anything except the pattern.|
|[...]||Matches any one of the characters enclosed.|
|[~...]||Matches any single character not enclosed.|
|- (hyphen)||Used inside brackets to specify a range for a single character.|
|, (comma)||Separates two patterns.|
|` (reverse quote)||Escapes special characters (reads next character literally).|
The following command tests a string to see if it begins with the character N:
Command: (wcmatch "Name" "N*")
The following example performs three comparisons. If any of the three pattern conditions is met, wcmatch returns T. The tests are:
Does the string contain three characters?
Does the string not contain an m?
Does the string begin with the letter “N”?
If any of the three pattern conditions is met, wcmatch returns T:
Command: (wcmatch "Name" "???,~*m*,N*")
In this example, the last condition was met, so wcmatch returned T.
Using Escape Characters with wcmatch
To test for a wild-card character in a string, you can use the single reverse-quote character (`) to escape the character. Escape means that the character following the single reverse quote is not read as a wild-card character; it is compared at its face value. For example, to search for a comma anywhere in the string “Name”, enter the following:
Command: (wcmatch "Name" "*`,*")
Both the C and AutoLISP programming languages use the backslash (\) as an escape character, so you need two backslashes (\\) to produce one backslash in a string. To test for a backslash character anywhere in “Name”, use the following function call:
Command: (wcmatch "Name" "*`\\*")
All characters enclosed in brackets ([ . . . ]) are read literally, so there is no need to escape them, with the following exceptions: the tilde character (~) is read literally only when it is not the first bracketed character (as in "[A~BC]"); otherwise, it is read as the negation character, meaning that wcmatch should match all characters except those following the tilde (as in "[~ABC]"). The dash character (-) is read literally only when it is the first or last bracketed character (as in "[-ABC]" or "[ABC-]") or when it follows a leading tilde (as in "[~-ABC]"). Otherwise, the dash character (-) is used within brackets to specify a range of values for a specific character. The range works only for single characters, so "STR[1-38]" matches STR1, STR2, STR3, and STR8, and "[A-Z]" matches any single uppercase letter.
The closing bracket character (]) is also read literally if it is the first bracketed character or if it follows a leading tilde (as in "[ ]ABC]" or "[~]ABC]").
Note! Because additional wild-card characters might be added in future releases of AutoLISP, it is a good idea to escape all nonalphanumeric characters in your pattern to ensure upward compatibility.
- JTB FlexReport (license reports)
- SmartPurger (automate and run script on multiple drawings)
- JTB CAD Automation Tools
- SSMPropEditor (edit multiple sheet properties at the same time)
- DwgNotes - Add and edit drawing notes
- DwgInfoTip - Show metadata in Windows Explorer
- DWG Columns - Show metadata in Windows Explorer
- Sheet Set Manager Path Edit
- HTools - AutoCAD productivity tools
- HVACPAC - AutoCAD plug-in for HVAC and Piping work
- Close License Borrowed dialog boxes automatically freeware
- Automatically close Select Shape File dialog boxes freeware
- AutoCAD/ADT/ABS/ACA/AMEP Palette Auto-hide Speed freeware.
- Background color changer for OSNAPZ - link.
- DWF Print
- ACA/ADT/ABS/AMEP ADTListDefinition. Import, create and export ListDefinitions quick and easy.
- RemIcons.lsp - Removes the icons Buzzsaw, RedSpark, Point A and FTP in Open dialog box. Or download the following files that can be run without AutoCAD running: remicons.vbs and addicons.vbs. Now for AutoCAD 2002 LT. Download the following files: remiconsLT.vbs or for only RedSpark remRedSparkLT.vbs
More resources on JTB World
- 2015-05-26 JTB Steel 1.2.1 steel shape drafting app for AutoCAD released
- 2015-04-21 Spiro1.2 released
- 2015-04-14 JTB CAD Automation Tools 4.2 released. Batch create and update drawings. For example change title block text on hundreds of drawings automatically.
- 2015-04-14 JTB Sheet Set Creator 1.3 released
- 2015-04-13 JTB Align Plus 3.5 app for AutoCAD released
- 2015-04-13 JTB Text Bubble Plus 2.1 and Text Bubble 2.5 released
- 2015-04-13 SmartPurger 3.6 released. Script and batch processing for AutoCAD
- 2015-04-13 Palette Auto-hide Speed 1.4 released. Translated tooltips for AutoCAD.
- 2015-04-13 TransTips 1.2 released. Translated tooltips for AutoCAD.
- 2015-04-12 JTB FlexReport 9.2 released. Time to upgrade or request a free fully functional trial. Your network license assessment companion.
- 2015-04-12 JTB FlexReport LT 1.2 released
- 2015-03-20 OffsetInXref 1.2 released. Better Offset for AutoCAD.
- 2015-03-20 OsnapzBG 1.2 released
- 2015-03-20 License Borrowed Dialog Closer 1.0.1 released
- 2015-03-20 Catenary for AutoCAD 1.0 released
- 2015-03-20 DwgNotes for AutoCAD 1.2 released
- 2015-03-20 DwgInfoTip 1.4 released
- 2015-03-20 DimNotes for AutoCAD 1.3 released
- 2015-03-20 DimensionPatrol 1.3 released. Highlight edited dimensions for AutoCAD.
- 2015-03-20 DigSigStamp for AutoCAD 1.3 released
- 2015-03-20 Batch Publish for AutoCAD 2.0 released. Mass produce PDF and/or DWF.
- 2015-03-20 JTB Change Title 1.0 for AutoCAD released
- 2015-03-18 SSMPropEditor 5.2 released. Makes it easy to edit properties on multiple sheets in AutoCAD Sheet Set Manager. Request a free fully functional trial.
- 2015-03-16 JTB Current Folder 1.2 for AutoCAD released
- 2015-02-23 DWG Columns 2.1 released
- 2014-12-21 Engco for rebar detailing released
- 2013-05-05 HVACPAC AutoCAD plug-in for HVAC and Piping work
- 2013-04-09 UnitCAD for AutoCAD, plug-in for AutoCAD automation with parameters
- 2013-02-12 HTools AutoCAD productivity tools