Last active
June 19, 2025 18:12
-
-
Save ncalm/3d7db1aa853592d131ed54c35c811ae9 to your computer and use it in GitHub Desktop.
Enabling Python and Regular Expressions in Power Query in Excel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Here's an example of how this pyscript app works in the browser: | |
| https://owenprice.pyscriptapps.com/pq-regex/latest/?txt=abc123def456&pattern=%5Cd%2B | |
| To clone the project and modify, create an account on pyscript.com and clone this project: | |
| https://pyscript.com/@owenprice/pq-regex/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let | |
| Source = RegexExtract("abc123def456", "\d+") | |
| in | |
| Source |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let | |
| RegexExtract = (txt as text, pattern as text) => | |
| let | |
| baseUrl = "https://owenprice.pyscriptapps.com/pq-regex/latest/", | |
| url = baseUrl & "?txt=" & | |
| Uri.EscapeDataString(txt) & | |
| "&pattern=" & | |
| Uri.EscapeDataString(pattern), | |
| html = Web.BrowserContents(url, [WaitFor=[Timeout=#duration(0, 0, 1, 0)]]), | |
| parsed = Html.Table( | |
| html, | |
| {{"Match", "div#output *"}} | |
| ), | |
| matches = List.Select( | |
| parsed[Match], | |
| each _ <> "" and _ <> "No matches" and _ <> "Invalid regex pattern" | |
| ) | |
| in | |
| matches | |
| in | |
| RegexExtract |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment