Version: Unity 7.0 Alpha (7000.0)
Language : English
Default formatter
List formatter

Is Match formatter

Choose between two outputs based on whether a value matches a regular expression.

The Is Match formatter evaluates a regular expression against the placeholder value and outputs one of two formats. Apply it explicitly with the name ismatch. The expression goes in the options, in parentheses; the format provides the match output and the no-match output, separated by the split character. Both the match and no-match output are required.

To use braces and parentheses as character literals in your pattern, escape them with a backslash. For example, \{, \}, \(, \).

You can configure settings on the formatter instance. Set the RegexOptions (for example, IgnoreCase) to control matching. Change the split character or the placeholder name for matches (the default is m). Refer to Configure Smart Strings for more information on formatter configuration.

Anatomy of the ismatch formatter syntax.
Anatomy of the ismatch formatter syntax.

The first format is used when the value matches; the second is used otherwise. You can output the regular expression’s matching groups with a special placeholder named m: {m[0]} is the whole match and {m[1]}, {m[2]}, and so on are the captured groups.

Smart String Argument Result
{0:ismatch(^.+123.+$):Okay - {}\|No match content} "Some123Content" Okay - Some123Content
{0:ismatch(^.+123.+$):Fixed content if match\|No match content} "Some123Content" Fixed content if match
{0:ismatch(^.+999.+$):{}\|No match content} "Some123Content" No match content
{Currency:ismatch(\p{Sc}):Currency: {m[0]}\|Unknown} "€ Euro" Currency: €

Combine it with the List formatter to test each item in a collection:

Smart String Argument Result
{0:list:{:ismatch(^100\|200\|999$):{:0.00}\|'no match'}\|, \| and } 100, 200, 300 100.00, 200.00 and ‘no match’

Additional resources

Default formatter
List formatter
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961