What are regular expressions and XPath?

This post is just an introduction for anyone visiting here for the first time who wondered what these things are.  In a nutshell here's how I would define them:

Regular Expressions

These are simply a method for finding text based on a pattern as opposed to searching for the literal text.  So if you wanted to find these four numbers 2, 4, 51, 178 in your text for example then instead of using four different searches you could use \d+ and this would find them all.  Of course it can get more complex than this, and my example is loaded with "what if" scenarios, but as a general rule this is all they are.  You can find some interesting articles on using regular expressions in Studio here:

You'll also find links to much more information on how to work with regex in the articles and the comments from many experienced users.  Don't be put off by anything that looks complex at first sight either.  Learning a few simple expressions can be incredibly powerful, and useful for you.  Studio can use regular expressions in the display filter, in simple search and replace, in creating custom verification checks, in creating text based filetypes, in handling embedded content with XML, excel or text filetypes as well as in a number of very handy openexchange applications.

So worthy of a little time getting familiar with the basics... the more advanced stuff will come.  You might even get hooked!

XPath

This is another method for finding stuff, but this time, in Studio, it's specifically used to find the contents of attributes and elements in an XML file.  This means you can use XPath to extract the translatable content of an XML file so you can translate it!  You can also use XPath to decide what information in the file you wish to display in the Studio preview when using a stylesheet.

As with regex it can get as complex as you like... but in it's basic form it's very simple and logical.  Take this simple XML file for example:

To extract the contents of the XML element <to> or <from> the XPath expression in your Studio filetype would be //to and //from.  Now Studio does this for you when handling simple elements and attributes as I've shown in this file.  But if the structure of the file becomes more complicated, or the rules for deciding whether the text should be translatable or not based on some logic written into the text itself, then XPath is probably the only you can get at it.

There are a couple of articles here introducing the concepts of XPath in Studio, as well as providing more links that may be useful if you delve into the inner workings of XPath to handle your XML filetypes.

I hope that explains reasonably well what this forum is all about, but if you have any questions, or just want to share something cool you created, then feel free to post into here.

Regards

Paul

1 Replies Latest Replies: 10 Mar 2016 10:10 AM by Jerzy Czopik

1 Reply


Related