Regular expressions in Power Fx #2840
Replies: 3 comments
-
I love it, Greg! Thank you! All I need now is the ability to take all the new imperative code I'm stuffing in App.Formulas into separate class files!! 🙏 ...just like the golden era in VB 4, 5, & 6! 🤠 |
Beta Was this translation helpful? Give feedback.
-
Greg - I think this is a great start. I'll get hands on with the expressions over the next few days and see how I get on. Question - I didn't see anything about compiling to SQL - this could be super useful for Dataverse formula columns Common issue - user enters a phone number and we use the regex in a formula column to reformat the number to the standard needed for our autodialer, sms gateway etc. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
It's time to officially add regular expression support to Power Fx. Power Apps have had them for a while in the form of Match, MatchAll, and IsMatch functions.
Our challenge has been that .NET and JavaScript have significantly different regular expression engines. And add on to this that Excel has integrated PCRE2. Ideally, we'd like Power Fx to have a common regular expression language that can be used on any host and gives the same results. That has required a three pronged approach:
\r
as a newline character, JavaScript can be transpiled for freespacing.I'd love your feedback on the regular expression language choices made. We have been opinionated in some areas. For example, explicit capture is the default and named and numbered captures can't be used together (.NET and JavaScript disagree on numbering of named captures, explicit capture is a best practice and higher performance, and named captures are easier to read and maintain and we should be promoting their use). We have also tried to make things clearer, for example requiring a literal ^ to be escaped in a character class, rather than depending on location wihin the character class to determine the meaning.
Please review the draft regular expressions documentation.
The three most important pieces of code to review:
And if you are so inclined, here is the PR including this test file which may be worth reviewing.
Thanks for your input!
Beta Was this translation helpful? Give feedback.
All reactions