Regular expressions (regexes) are very powerful tools that help doing complex search and replace actions. Writing a regex can be difficult. memoQ's Regex Assistant window offers useful regexes, and it also helps you build, test and save your own.
How to get here
To open Regex Assistant, click the icon in any memoQ text field where you can use regular expressions (in the Quick Find and Advanced Find and Replace windows, and the translation editor, you need to turn on regex mode first):
- Quick Find window – Find what and Replace with fields
- Advanced Find and Replace window – there is a separate button here
- Translation editor – Source and Target filter fields above the grid
- Edit QA settings window – Source, Target, and Correction fields on the Regex tab
- Add new length information rule window – Regex field
- Edit segmentation rule set window – text fields under the Rules and Exceptions lists in Advanced view
- Edit auto-translation rule set window – text fields under the Auto-translation rules and Custom lists lists
- Regex tagger – Regular expression and Display text fields
- Regex text filter window – Paragraph end and Paragraph start fields on the General tab, Rule field on the Paragraph tab, Before, After, and Rule fields on the Include/Exclude tab
- ZIP filter – text field under the Pattern list
- MSG filter – Regular expression field on the Email threads tab
What can you do?
Use a regex from the Regex library
Open the Regex library dropdown, and choose a regex from the list. To filter for one or more regexes: Type something into the text box above the list. If the text you typed can be found in some regexes' name or label, the list will only show those. You will see the matching labels and regex name parts highlighted in yellow:
Click the regex you need. It appears in the Find what field. If it replaces something (for example, converts dates to a different format), a replacement string appears in the Replace with field. You can edit these as needed.
memoQ remembers the last regex you choose from the library: It appears at the top of the list, under the Last selected regex heading.
To see what the regex does, type or paste text into the Testing ground field. If you are working in the translation editor, you can also select segments in the grid, and click the Insert source segments or Insert target segments link under the Testing ground to copy text from memoQ. Parts that match the regex in the Find what field appear highlighted. If there is something in the Replace with field, the After replace field shows the expected results.
If the regex works well, click the Insert regex to button. memoQ inserts the regex into the text box where you clicked the Regex Assistant icon. If replacing is also possible in that window, memoQ inserts the string in the Replace with field, too.
If memoQ cannot find out where to insert the regex, the button becomes inactive. Click the text box you need, and the button becomes clickable. Or, copy the regex to the clipboard and paste it manually.
Build a regex
If the Regex library does not have the regex you need, you can build your own. Regexes have their own syntax (memoQ uses the .NET flavor). This page explains the basics, but you can just open the Regex cheat sheet dropdown, and click something in the list. The regex element (token) you clicked appears in the Find what field. Keep adding elements from the cheat sheet as needed. Use the Testing ground to see if your regex does what you need.
Save a regex into the Regex library
At first, the Regex library only contains built-in regexes. To add your own regex: Build or copy it in the Find what field, and click the Add to Regex library link. In the Add to Regex library window, give it a name. Enter labels (categories that help you searching for regexes) as needed. Put commas between labels. In the Description field, explain what the regex does - long and complex regexes are hard to understand. Then click the Add to library button. The regex appears in the top section of the Regex library, named Your saved regexes.
Edit your regexes in the Regex library
Under the Find what and Replace with fields, click the Edit your Regex library link. The Edit your Regex library window opens.
The list only shows the regexes you added to the library – you cannot edit or delete memoQ's built-in regexes.
To edit a regex: Click its Edit icon. In the Edit regex window, change the regex in the Find what or Replace with field as needed. Change the Name, Labels, and Description fields' content as needed. (Put commas between labels.) To save your changes: Click the OK button. To discard them: Click the Cancel button.
To delete a regex: Click its Delete icon. In the Delete regex window, click the Delete button. Or, to keep the regex, click the Cancel button.
To delete two or more regexes: Check their check boxes. Under the list, click the Delete selected regexes link.
Be careful: If you delete a regex, it is gone. You cannot bring it back – only if you exported it from your Regex library earlier.
To add or remove labels: Check one or more check boxes as needed. (To select or unselect all regexes, check or clear the check box in the column header.) Under the list, click the Manage selected labels link. The Manage labels window opens.
This window shows the selected regexes' labels and the number of selected regexes that have those labels. For example, in the image above:
- the user selected three regexes before opening the Manage labels window,
- the label 'saját' is on two of them, and
- each of the labels 'mod', 'from Sanyi', and 'date conv' is on one of them.
To remove a label from all the selected regexes: Click its Remove icon.
To add a label to all the selected regexes: Type a label into the text box under the list, and click the Add button.
To save your changes: Click the OK button. To discard them: Click the Cancel button.
Export or import your regexes
To save your regexes into an XML file: In the Edit your Regex library window, check the regexes' check boxes as needed. Under the list, click the Export selected regexes link. If you do not want to share your regex labels with others, check the Remove labels on export check box before you click the Export button. Browse to a folder, and save the file as needed.
To add regexes to your library from an XML file: You need an XML file with a somebody's exported Regex library. In the Edit your Regex library window, under the list, click the Import library link. Browse to the file, and open it.
In the Import regexes window, check or clear the regexes' check boxes as needed.
To remove labels from all the selected regexes: Check the Remove labels on import check box.
To add labels to all the selected regexes: Type the labels into the text box under the list. (Put commas between them.)
When you are done, click the Import selected button.
If an imported regex has the same name as an existing one in your library, memoQ puts a number after its name – for example, "my regex (1)". You can rename it as you wish.
When you finish
You can leave the Regex Assistant window open while you work. Drag it to a place where it does not disturb you – or, if you are sure you do not need it, click the white X icon in the window's upper right corner.