The Regex filter servers as a general purpose text filter that allows for selecting any lines of text matching a regular expression pattern. The Regex filter is a tool for a project manager that allows him to define what exactly he wants to extract. So he must provide the regex pattern.
Note: It’s never selected as a default filter for any type of files (it’s not linked to any extension).
It allows to parse a file line by line and compare with the pattern. When the match is found the line will be processed as a segment for translation. However in nearly all cases only a part of the line needs to be extracted for translation. That’s why the regex pattern must include at least one regex group (the part in parentheses) that references the text for translation.
Regex groups have their numbers. Using the group number allows the user to choose, which exactly group should be translated. Also it helps the filter to find a position where the translation must be put back after the file is reverted.
The default pattern of the Regex filter is: (.*). So basically it works as a plain text filter extracting all the text (each line).
'header' => [
'view_profile' => 'View profile',
'logout_btn' => 'Logout'
// MAIN NAVIGATION
'main_nav' => [
'dashboard' => 'Dashboard',
'buy_sell' => 'Buy/Sell',
'accounts' => 'Accounts',
'tools' => 'Tools',
'settings' => 'Settings',
We want to extract content in between the quotes: View profile, Logout, Dashboard etc. First find the lines using a regex that matches any number of space characters (spaces or tabs), then an apostrophe, any number of characters, another apostrophe, zero or more space characters, a literal string of =>, zero or more space characters, apostrophe, one or more characters ending with a literal apostrophe.
There may be any number of characters after the last apostrophe to the end of the line. The pattern below will do the trick:
Having the lines of interest we can specify the text we actually want to translate. We can simple define a group (the one and only in this case) by surrounding the part referencing to the text with parentheses:
This is how the entered regex pattern will affect the filter: