Regular Expressions for Translations

Usually, regular expressions for translation are used for 2 types of entities: Sender ID & Message Text.

Before moving on to specific examples, we need to become familiar with regular expressions.

At the beginning, it is necessary to mention that regular expressions in our system are used in Python format. And the main task of regular expressions is to search for occurrences in the parameters of the incoming message. In other words, this sets the filter for applying the translation. But for the correct configuration, it is necessary to determine the pattern of messages for which this routing is required.

Once a pattern is defined and a regular expression is constructed based on it, there are several ways to check its correctness.

1st - Start/Reference/Regular Expressions interface. You can find detailed step-by-step description in this screenshot:

Also, you can find detailed description of this interface in our manual.

2nd - To create a test translation rule and perform a simulation. You can check whether this rule will be applied, or find out the reason for the opposite.

3rd - To use site https://regex101.com/. You can find detailed step-by-step description in this screenshot:

And now we can look at some examples of translation for the two mentioned earlier entities.

1. Translations for sender ID.

1.1 Apply translation for any alphanumeric number to some specific value.

In the “Sender ID pattern:” you need to specify:
^\D*$ - it means any non-digit character contains in the sender id.

In the translation field you need to specify required value, to which the number should be translated.

1.2 Apply translation for a specific number to some specific value.

For example, you need to translate “Facebook” sender ID to “Meta”. In the “Sender ID pattern:” you need to specify:
Facebook
In the Translation field, you need to specify:
Meta

1.3 Apply translation for set of parameters (Sender ID and text message) to specific value.

For example, for some specific number & message text, containing 4 digits OTP code, you need to translate sender ID to “Google OTP”.
In the “Sender ID pattern” you need to specify required sender number.
In the “Text pattern” you need to specify a regular expression that will detect 4 digits in a row in the message text:
^(.*)(\d{4})(.*)$
In the “Translation” field, you need to specify “Google OTP”.

2. Translations for message text.

2.1 Apply translation for any OTP message, after which the required text will contain the pattern: “Your OTP code is *”

In the “text pattern” you need to specify:
^(.*?)(\d{4})(.*?)$

Kindly note that exact amount of digits in a row configurable with the value specified in the {}. For example, to specify a range from 4 to 8 digits, you need to use {4,8}.

In the translation, you need to specify:
Your OTP code is \g<2>

2.2 Apply translation to replace some specific word in the text.

In the “text pattern” you need to specify:
^(.*?)(word_that_needs_to_be_replaced)(.*?)$ 

If it is required to translate different words, you can specify all of them in the (), for example (word1|word2|word3).

In the “translation” you need to specify:
\g<1> word_to_replace_with \g<3>

2.3 Apply translation to exclude any link starts with www from the text.

In the “text pattern” you need to specify:
^(.*?)(\w*[.]\w*[.]\w{2,3}[/]\w*)(.*?)$

In the translation, you need to specify:
\g<1>\g<3>.

If it is required to specify an exact word or phrase to replace the link, you can specify it between the groups. For example, \g<1> link word \g<2>

If you’ll need any further assistance, feel free to contact Alaris support team.

AKBSMS - Alaris Knowledge Base

Related Questions:
How to configure "Text pattern" in "Translation Rules"?
How to configure "Sender pattern" in "Translation Rules"?
How to check the correctness of a regular expression?
How to exclude link from the text?
How to apply translation with the set of parameters?

Link to this article: https://helpdesk.alarislabs.com/en/knowledge_base/article/271/category/134/