Convert memoQ Regex Assistant libraries to RegexBuddy!
Another way to share regular expression resources to work on other platforms
As those who have attended my talks on the memoQ Regex Assistant or seen the recordings probably know, I put a lot of emphasis on making expression solutions available for use in other tools or environments. For a few years now, I’ve been sharing an XSL script and instructions for converting the libraries to a readable HTML file or showing how to view your regex library in Microsoft Excel.
Recently I’ve been looking at the popular RegexBuddy to evaluate its potential for some of my teaching plans. Paul Filkin at RWS recommends this tool often for those who want colorful visual assistance to understand how expressions work (or don’t in some cases), and I revisited his recommendation, among other reasons because it can also be helpful in translating between dialects of regular expressions that might be used on diverse platforms. It could also be a useful solutions library tool for other platforms.
But I faced the challenge of how to share my extensive collections of translation- and text review-related regexes with people who use RegexBuddy. I had a look at the export format for that tool’s libraries, and thank all the gods it’s XML, just like for the memoQ Regex Assistant.
Well, different tags and structures, but XML nonetheless. That means it’s pretty easy to script a conversion from the memoQ Regex Assistant XML to RegexBuddy XML do the memoQ solutions can be used from the other platform.
And here’s a look at a little test of that I did with 176 regexes:
In “RegexBuddy World”, the .NET flavor of regular expressions that memoQ uses is called C# (.NET 2.0-8.0)
because most of that tool’s users are programmers who concern themselves with the relevant dialects for a given programming language or environment. Language services people don’t typically have to think about this sort of thing, but it might come up when taking a solution from Trados Studio or memoQ, for example, and trying to use it in the Java-based Wordfast. RegexBuddy actually has some features that might help with that.
The script below can be copied and pasted into a text file and saved under whatever name you line with the *.xsl
extension. Conversions can be performed with free online tools (web pages) such as the one at freeformatter.com (a nuisance because it leaves off the necessary XML declaration at the top of the file and you have to paste it in manually) or the free XML Notepad from Microsoft, which is my preferred choice.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<rxb:regexbuddy version="4.14" xmlns:rxb="http://www.regexbuddy.com/regexbuddy4E.xsd">
<libraryfile>
<xsl:for-each select="/RegexLibrary/Items/Item">
<action purpose="replace">
<flavor><builtin>csharp20</builtin></flavor>
<regex><xsl:value-of select="FindRegex"/></regex>
<replace><xsl:value-of select="ReplaceRegex"/></replace>
<description>
<xsl:value-of select="Name"/>
<xsl:text>
</xsl:text>
<xsl:for-each select="Labels/Label">
<xsl:value-of select="Value"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
<xsl:text>
</xsl:text>
<xsl:value-of select="Description"/></description>
</action>
</xsl:for-each>
</libraryfile>
</rxb:regexbuddy>
</xsl:template>
</xsl:stylesheet>
I had to play a few games with the script formatting so it would display right on Substack, so don’t be surprised if you paste it into Notepad++ or a similar editor and it looks brutally condensed:
I’m not particularly fond of the layout and some other aspects of Regex Buddy, but it’s a good tool that offers a lot of nice features for understanding one’s regex solutions better and for organizing them, and it can be used by people for any regex-capable software under Windows.
What about other operating systems like Linux or MacOS? The RegexBuddy site talks about a means of running this Windows-based tool under Linux (Wine), and Code Weavers seem to offer a solution for MacOS with their Crossover™ tool. I don’t have the equipment to test these, but if relevant to you, you might want to give that a shot yourself. If there are better regex library apps for those other operating systems and they use XML or other text-based exchange formats, appropriate converters can be scripted without much difficulty.