In some cases, you may want to "cut off" certain dimension values from your data sources as you map them into one of your custom dimensions. This process can also be referred to as truncating. In this particular example, we're going to essentially shorten the dimension value we want to map to our custom dimension to only be (at most) 20 characters long. There are more advanced applications of this type of regex, but this is a basic but not at all uncommon use case.
First, edit your custom dimension and create a new rule.
Choose which other dimension you would like to capture values from and use in your custom dimension.
Change the condition of WHEN from "exactly matches" to "matches regex".
In the input field of WHEN, enter the following regex:
^(.{20}).*$
Make sure that, for THEN [DIMENSION NAME] IS, you choose "regex match" and "capture group 1".
You're all done!
NOTE: here is some clarification on the regex characters used:
^
denotes the start of a string()
defines a capture group.
denotes any character, a "wildcard" character{}
defines an amount of characters to match against (usually only used for 2 or more finite numbers of characters)*
denotes any amount of characters to be matches against$
denotes the end of a string