h1. Regex patterns {{>toc}} In various modules of a system you can use *string replacement by regular expressions*. The examples of such modules are: * [[Number replacement]] This functionality is used to replace the original string by certain rule. Most often this is used to manipulate with inbound and outbound numbers, for example: * cutting off technical prefix * adding technical prefix h2. Rule formats. Replacement rules can be defined using various syntaxes: * [[Sed syntax|sed]] * [[Perl syntax|perl]] * [[Literal syntax|literal]] h2. How number replacement is done. Smartswitch takes original sring and begins iteration over configured rules according to rule priorities. Rules with less priority value are handled first. In web-interface rules by default are sorted according to priority. Therefore, iterating replacement rules will be done from top to bottom. For each rule system tries to find a match of original string to a *regular expression*, configured inside rule. To find a match, specified *format* is used and a value of *regular expression*. After match has been found, a replacement is done according to configured *rule application options* and a value inside *replace* field. After replacement has been done, the original string is replaced with new one. In case if option *continue* is not checked - search and replace stops. In case if set - system moves to a next rule from the list according to priorities. In case if match according to *regular expression* hasn't been found for current rule - system moves to a next rule from the list according to priorities. h2. Rule application options for replace patterns. * *only first*. This option controls, whether or not only first occurrence should be replaced. For example, rule defined as _777 -> 888_, original string is _17772777_. Then this option is disabled, string is replaced to _18882888_. When this option is enabled, string is replaced to _18882777_. * *don't copy*. This option controls, whether a part of original string which didn't match should be presend is resulting string or not. For example, the rule defined as _777 -> 888_, original string is _17772434_. When this option is disabled, string is replaced to _18882434_. When this option is enabled, string is replaced to _888_. * *continue*. This option controls, whether or not system will move to next rule in a list after the current rule is applied. For example, the rule defined as _777 -> 888_, original number is _17772434_. When this option is disabled, string will be replaced to _18882434_ and replacement will stop. When this option is enabled, string will be replaced to _18882434_ and replacement will continue according to a next configured rule in a list. [[Regex шаблоны|Русский перевод]]