Regex Assistant
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. It appears in the Find what field. If the regex 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.
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 Copy regex to clipboard icon next to the Find what field, and paste the regex into memoQ where you need it. Do the same with the Replace with field if there is one.
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. Give it a name, and click the Add to library button. It appears in the top section of the Regex library, named Your 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. To rename the regex: Edit the Name field's content. 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.
Be careful: If you delete a regex, it is gone. You cannot bring it back – only if you exported it with your Regex library earlier.
Export or import your regexes
To save your regexes into an XML file: In the Edit your Regex library window, under the list, click the Export your library link. 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.
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.