Skip to content

Instantly share code, notes, and snippets.

@ncalm
Last active June 19, 2025 18:12
Show Gist options
  • Save ncalm/3d7db1aa853592d131ed54c35c811ae9 to your computer and use it in GitHub Desktop.
Save ncalm/3d7db1aa853592d131ed54c35c811ae9 to your computer and use it in GitHub Desktop.
Enabling Python and Regular Expressions in Power Query in Excel
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/
let
Source = RegexExtract("abc123def456", "\d+")
in
Source
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