Skip to content

Instantly share code, notes, and snippets.

@Hugoberry Hugoberry/regex.m
Last active Mar 9, 2020

Embed
What would you like to do?
let
fx=(x,y)=>
Web.Page(
"<script>
var x="&x&";
var y=new RegExp('"&y&"','g');
var b=x.match(y);
document.write(b);
</script>")[Data]{0}[Children]{0}[Children]{1}[Text]{0}
in
fx("""hello012中国1235""","\\d+")
@SamWoolerton

This comment has been minimized.

Copy link

SamWoolerton commented Jul 24, 2019

You can shrink down the whole thing above to just
(text, pattern) => Web.Page("<script>document.write(new RegExp('"& pattern &"').test('"& text &"'))</script>")[Data]{0}[Children]{0}[Children]{1}[Text]{0}

I also recommend using this as a function that you call separately, as it'll keep things way cleaner

@szebrowski

This comment has been minimized.

Copy link

szebrowski commented Feb 2, 2020

You can shrink down the whole thing above to just
(text, pattern) => Web.Page("<script>document.write(new RegExp('"& pattern &"').test('"& text &"'))</script>")[Data]{0}[Children]{0}[Children]{1}[Text]{0}

this only gets you a true/false output

@szebrowski

This comment has been minimized.

Copy link

szebrowski commented Feb 2, 2020

My take on the snippet, ready to paste to as new query:

let   fx=(text,regex)=>
    Web.Page(
        "<script>
            var x='"&text&"';
            var y=new RegExp('"&regex&"','g');
            var b=x.match(y);
            document.write(b);
        </script>")[Data]{0}[Children]{0}[Children]{1}[Text]{0}

in
fx

basically it's the same, it's only easier to use if you don't know power query :)

edit: check the performance of this solution, I think this it is super slow for bigger data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.