Regular expressions for Dynamo
Regular expressions provide a powerful, flexible, and efficient method for processing text. The extensive pattern-matching notation of regular expressions enables you to quickly parse large amounts of text to find specific character patterns; to validate text to ensure that it matches a predefined pattern (such as an email address); to extract, edit, replace, or delete text substrings; and to add the extracted strings to a collection in order to generate a report. For many applications that deal with strings or that parse large blocks of text, regular expressions are an indispensable tool. Regular Expression Language - Quick Reference
Regular expressions are now available in Dynamo with this package. Package based on the regular expression engine, which is represented by the System.Text.RegularExpressions.Regex object in .NET
Assume that a mailing list contains names that sometimes include a title (Mr., Mrs., Miss, or Ms.) along with a first and last name. If you do not want to include the titles when you generate envelope labels from the list, you can use a regular expression to remove the titles, as the following example illustrates.
The regular expression pattern (Mr\.? |Mrs\.? |Miss |Ms\.? ) matches any occurrence of "Mr ", "Mr. ", "Mrs ", "Mrs. ", "Miss ", "Ms or "Ms. ". Regex.Replace node replaces the matched string with empty string; in other words, it removes it from the original string.
Accidentally duplicating words is a common error that writers make. A regular expression can be used to identify duplicated words, as the following example shows.
The Regex.Matches method is called with regular expression options set to IgnoreCase. Therefore, the match operation is case-insensitive, and the example identifies the substring "This this" as a duplication.
Note that the input string includes the substring "this? This". However, because of the intervening punctuation mark, it is not identified as a duplication.
The package is available on the Dynamo Package Manager. Also you can install them manually by following the instructions under the Alternative installation methods section of this document.
If you prefer to install one of the more experimental/work-in-progress builds, you can still follow the instructions below.
- Download the latest release from the Releases page
- Unzip the downloaded file
- Once unzipped, double-check that all
.dllfiles in the package'sbinfolder have been unblocked - Copy the package folder to the location of your Dynamo packages :
%appdata%\Dynamo\Dynamo Core\2\packagesfor Dynamo Sandbox, replacing2with your version of Dynamo%appdata%\Dynamo\Dynamo Revit\2\packagesfor Dynamo for Revit, replacing2with your version of Dynamo
- Start Dynamo, the package should now be listed as in the library and in Dynamo's
Package Manager
This project requires the following applications or libraries be installed :
Dynamo : version 2.1 or later
.NET : version 4.7.1 or later