Table of Contents
Regular Expression (Regex)
Table of Contents
A regular expression (regex or regexp) is a sequence of characters that helps you search in text (strings). Various systems use Regex for field validation and for find & replace operations on text (strings). Regex is common in computer science. See Wikipedia Regex for more details.
Regex is used in Fotoware Alto Business Rules and field-format validations. Regex is best suited when you have a well-defined file-naming convention in place.
Online tool to test & validate regular expressions: www.regexr.com
- Make sure PCRE is selected in the top right corner
- Switch between Details and Explain tab
Get the specific product code from the filename
The product code must be 14 characters long and appear at the beginning.
(?<productCode>^(F-|G-|V-)[^_]*?)_()
Get any product code from the original filename
(?<productCode>^[0-9]{2} [0-9]{3} [^-]*)-(?<filename>.*)
Short Explanation:
- Create a group "productCode"
- Start at the beginning ^
- Get the first two numbers
- Get the following three numbers
- Get the rest until you find a dash -
| Input | Original File name | 01 747 7715 7754-Set_HighRes_4035.jpg |
| Output | productCode (from Regular Expression) | 01 747 7715 7754 |
| Output | filenmae (from Regular Expression) | Set_HighRes_4035.jpg |
Get code that starts with MT-
(?:MT|\G)-(?<mediaType>[A-Z\s]{3,4})
Short Explanation:
- Create a group "mediaType"
- Get a code that starts with MT
| Input | Original File name | Summer-Campaign_MT-EMOS-Set_HighRes_4035.jpg |
| Output | mediaType (from Regular Expression) | MT-EMOS |