CAD Studio - CAD/GIS/PLM solutions
English Deutsch Cesky Slovensky

srxTEXT srxText - search/replace AutoCAD drawing texts

Advanced replacing of DWG texts using substrings, regular expressions and tables

srxText as universal text replacement engine

SRXTEXT is a LISP utility for AutoCAD 2000/i, 2002-2016, which can search and/or replace drawing texts (TEXT, MTEXT, DIMTEXT, ATTRIB, ATTDEF).

You can choose from exact string match, substring match/replace or regular expressions. For the regular expression functionality, AutoCAD Express Tools may be required (part of AutoCAD installation). You can search (and replace) the whole drawing, any specified layer or selected objects. SRXTEXT zooms to any matching text and offers to Replace, Autoreplace (Yes to all), Skip to next or Exit the search/replace loop.



The preferred SRXTEXT2 command uses VBscript regular expression engine (instead of Express Tools) to perform regular exp. replacements. Use the older version SRXTEXT only for compatibility reasons. You can also force srxText to VBscript mode by setting the LISP variable:

(setq _srxRegEx "VB")

The "CSV" version SRXTEXTCSV loads the search-replace string pairs from a .CSV text file so you can predefine complex replacements e.g. in Excel. The expected .CSV file is in the format:

(sample file included)

Since version 1.5 the quotes are optional and the delimiter can be "," or ";".

The CSV version is in Trial mode only (first 2 pairs are processed). Use the CADSTUDIOREG command to authorize it.

SRXMISSING is a special command which can identify texts (numbers) missing from a given numeric interval. If you should have e.g. doors numbered 1-100, it can find the door(s) with forgotten number in a series.

Regular expressions

Working with regular expressions is an important part of the srxText functionality. Please note that the regular expression syntax differs in the old Express Tools version and in the VBscript version of the command - SRXTEXT2.

Using regular expressions you can perform complex replacements like changing:

Part:457/03667 Code:D19

For this case you would use the search and replace strings:

	Part:\2/\3 Code:\1
and in SRXTEXT2:
	Part:$2$3 Code:$1

SrxText supports a subset of standard regular expression syntax, SrxText2 supports the whole VBscript regex syntax. The subset:

. 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 or e.g. [0-9]
\( 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. 


  • You can append strings to the beginning of your texts:
  • or to the end of your texts:
    in SRXTEXT2:
  • You can replace just the first occurrence of a substring in text:
    	search: \(.\)oldtext\(.\)
    	replace: \1newtext\2
    in SRXTEXT2:
  • Another example of complex replacements:
    KWD-5-3, KW-4-2, KWP-1-5
    change to:
    KCD-5-1, KC-4-1, KCP-1-1
    	search: \(.\)W\(.*\)\-\(.\)\-\(.\)
    	replace: \1C\2-\3-1
    in SRXTEXT2:
  • Cutting the number of decimal places to 1:
    	search: \([0-9]*\)\.\([0-9]\)[0-9]*
    	replace: \1.\2
    in SRXTEXT2:
  • Adding a thousands separator (",") to numbers.
    	search: -?\([0-9]+\)\([0-9][0-9][0-9]\)
    	replace: \1,\2
    in SRXTEXT2:

    (repeat it for million/billion/... triplets)

  • Delete all text after the first period in text:
    	search: ^\([^\.]*\)\..*
    	replace: \1.
    in SRXTEXT2:
  • Replace trailing "A"s with "B"s:
    	search: \(.\)A$
    	replace \1B
    in SRXTEXT2:
  • Delete trailing spaces:
    	search: \(.\) +$
    	replace: \1
    in SRXTEXT2:
    	(.) +$
  • Delete color control codes in MTexts:
    	search: \(.\)\{\\C[0-9]+;\(.\)
    	replace: \1\2
    in SRXTEXT2:
  • Adding trailing text to texts not containing "*":
    	search: ^\([^\*]+\)$
    	replace: \1 NewTrailingText
    in SRXTEXT2:
    	$1 NewTrailingText
  • Erasing the first character in the text:
    	search: ^.\(.*\)
    	replace: \1
    in SRXTEXT2:
  • Replacing hard returns with soft returns in MText:
    	search: \\P
    	replace: _    (single space character)
    in SRXTEXT2:

Replacements in scripts

You can use ScriptPro or other script processor to perform batch replacements on multiple DWG files. The script could look like e.g.:

(load "srxtext.vlx")

- or just -

(load "srxtext.vlx")
(srxtext "Substring" "oldtext" "newtext" "All")

Tip 1:
MTEXT objects can contain hidden control character codes, so they may appear to not meet the exact matches (btw, you can use SRXTEXT to remove these control characters)

Tip 2:
You can use srxText to add, modify or delete control characters in MText texts - changing the string height, color, font, width, etc. E.g. {\T2.0;XXX}

Tip 3:
set _SRXTEXTNOZOOM to T (true) to disable running zooms:
(setq _SRXTEXTNOZOOM T) set _srxTEXTCSVen to T (true) to use old "comma only" separators when processing CSV files

Tip 4:
SRXTEXTCSV honors the FILEDIA setting so you can enter the .CSV file name on the commandline (e.g. in batch scripts) with FILEDIA=0

Tip 5:
If you need to enter regular expression strings in menu macros, you cannot use backslashes, use (chr 92) instead. E.g. the LISP version of srxtext (replace "\\"->"|"):
(srxtext "Regular" (strcat(chr 92)(chr 92)) "|" "All")

Tip 6:
Use (setq _srxRegEx "VB") to force all srxText functions using regular expressions to the VBscript engine.


You cannot replace strings in text generated by Fields. Character case must match exactly (case-sensitive) - not in regular expressions.

Since version 1.1 you can replace MTexts longer than 256 characters.

Since version 1.4 you can enter the searched text by picking en existing text entity.

Since version 2.0 you can use the VBscript engine - default in the SRXTEXT2 command.

LISP interface

SRXTEXT contains also a LISP interface so you can use the srxText functionality in our LISP routines:

(srxTEXT "<mode>" "<search>" "<replace>" "<layers>")
(srxTEXT2 "<mode>" "<search>" "<replace>" "<layers>")
  • <mode> can be Substring or Regular or Exact (case sensitive)
  • <search> is the searched string
  • <replace> is the replacement string
  • <layers> can be "All", or a name of an existing layer, or "Select" to select objects interactively, or a selection set variable with selected objects returned value is the number of replacements done


(srxTEXT "Substring" "Ford T1" "Ford Galaxy" "All")
(srxTEXT "Exact" "Autocad" "AutoCAD" myselectionset)

in Czech (česky):

Regulární výrazy:
SrxText podporuje podmnožinu syntaxe standardních regulárních výrazů, SrxText2 podporuje celou syntaxy z VBscript. Podmnožina:

  • . odpovídá jakémukoliv jednomu znaku
  • * přípona - předchozí položka se může opakovat 0 nebo vícekrát
  • + přípona - předchozí položka se může opakovat 1 nebo vícekrát
  • ^ odpovídá prázdnému znaku na začátku řetězce
  • $ odpovídá prázdnému znaku na konci řetězce
  • [znaky] odpovídá jakémukoliv znaku dané třídy. Pokud je prvním znakem ^, odpovídá jakémukoliv znaku kromě dané třídy. Lze zadat rozsah znaků pomocí první-poslední, tedy např. [A-Z] určuje znaky velké abecedy nebo např. [0-9] číslice
  • \( označuje začátek zapamatovaného podvýrazu
  • \) označuje konec zapamatovaného podvýrazu
  • \číslice označuje text dříve zapamatovaný podvýrazem v N-té otevírací závorce. Podvýrazy lze odkazovat v řetězcích pro nahrazení.


SRXTEXT is a free/trial utility by CAD Studio, do not publish it online on other than CADstudio's web servers, do not sell, lend or exchange it.

Download the srxText application (for AutoCAD 2016-2000)

Full license - Buy srxText

Facebook Twitter Google+ YouTube LinkedIn
© 2016 CAD Studio a.s. | contact | webmaster | privacy