Rule - Regular Expression

  1. Home
  2. Translator++
  3. Parser Model Creator
  4. Rule – Regular Expression

Rule – Regular Expression

You can create a rule with Javascript’s Regular Expression.

You also need to include the modifier flag. For example, to capture every occurrence, you need to add the g modifier; otherwise, the parser will only capture one occurrence:


Use the Regular Expression Editor to help you write Regex

You can use an online regular expression editor to edit regex, for example,

Generating Regex with ChatGPT

Nowadays, you can easily generate regex using chat GPT. You only need to write the regex specifications you desire.

Sample prompt to generate regex

Capture Groups

In regex, any subpattern enclosed within the parentheses () is considered a group. For example, (xyz) creates a group that matches the exact sequence “xyz”.

Parser Model Creator allow you to capture specific groups from your regex.

Some regular expression editors can provide good information about what groups are generated from your pattern.

For example, in the following image, regex101 can tell me which group contains the string to be translated.

From that information, I can determine that the group ID is 1. Therefore, I can enter this same ID into the Capture Groups field.


Regular expression supports 4 types of action

  • Capture value
  • Capture then mask value
  • Mask value
  • Send to inner rule
Action type of the regular expression rule

Capture value

This is the default action. If “Capture value” is selected, then all strings found will be registered as translatable text.

Capture then mask value

This action adds an additional step beyond the default ‘Capture value’ action. If the ‘Capture then mask value’ action is selected, the parser will register the found text as translatable text and then mask that text so that it cannot be recognized by subsequent rules that will be executed.

This action is particularly useful when you use more than one rule. 

Mask value

If ‘Mask value’ is selected, the text that is found will not be registered as translatable text, but will be masked so that it will not be found by the next rule to be executed.

Send to inner rule

If ‘Send to inner rule’ is selected, then the text that is found will be sent to a inner-rule for further processing.

This is particularly useful when your pattern is very complex and you want to process it into more than one regular expression pattern.

You can edit the inner rule by pressing the Edit inner rule button.

Edit inner rule button, to edit the sub rule

In the inner rule, you can choose to use regular expression or JavaScript function. So, it is possible to use both Regular Expression and Javascript function at the same time in a single rule.

Inner rule can be Regular Expression or a Javascript function

Also, the depth of the inner rule is indefinite, so you can have multiple levels of inner rules. However, I do not recommend having inner rules that are too deep because it will slow down the parsing process, and your code may become harder to understand.

Was this article helpful to you? No Yes

How can we help?