Regular expressions in Dynamo Revit.
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.
.dll
files in the package’s bin
folder have been unblocked%appdata%\Dynamo\Dynamo Core\2\packages
for Dynamo Sandbox, replacing 2
with your version of Dynamo%appdata%\Dynamo\Dynamo Revit\2\packages
for Dynamo for Revit, replacing 2
with your version of DynamoPackage Manager
This project requires the following applications or libraries be installed :
Dynamo : version 2.1 or later
.NET : version 4.7.1 or later