Question
· Jul 9, 2018

Translate Pattern Match expression to Regex?

I'm trying write a JavaScript generator to perform pattern match validations using existing pattern match expressions in a legacy application.

I could make a server call to perform the pattern match operation but is there a way to automatically translate the pattern match expressions into RegEx expressions so I can perform the operation in JavaScript on the client to save making an Ajax call back to the server?

Thanks

Jay Ayliff

M-Tech

Discussion (2)0
Log in or sign up to continue

I've never seen anything like that in the docs before, just working with either regex or the pattern match operator. To get what you're looking for you may very well have to make those extra calls. Alternatively a cool project would be to make your own converter.  That'd be pretty interesting to do,  but before I'd look into it I'd like to make sure there isn't some function out there I've never heard of in Cache that does it. It never ceases to amaze me how many obscure functions exist out there for Cache that I have yet to discover.

Unfortunately, you're probably going to have to convert the patterns by hand, and the regex syntax is slightly different from the traditional pattern match syntax, starting with the fact that repetition count comes after the item being matched. For example the pattern 1.6N becomes the regex \d{1,6}.

Fortunately, once you've got your patterns converted to regexes, you can use the regexes from Caché code thanks to the $Locate and $Match functions, as well as the %Regex.Matcher class which provides a richer interface to regex functionality.