Porting invRegex.py to Javascript (Node.js)

后端 未结 6 1904
余生分开走
余生分开走 2020-12-16 03:16

I have been trying to port invRegex.py to a node.js implementation for a while, but I\'m still struggling with it. I already have the regular expression parse tree thanks to

6条回答
  •  半阙折子戏
    2020-12-16 03:57

    There already are plenty of good answers here, but I specifically wanted the generator part to work, which did not for you. It seems that you were trying to do this :

    //the alphanumeric part
    for (x of alpha()) for (y of numeric()) console.log(x + y);
    
    //or as generator itself like you wanted
    function* alphanumeric() {
        for (x of alpha()) for (y of numeric()) yield(x + y);
    }
    //iterating over it
    for (var i of alphanumeric()) {
        console.log(i);
    }
    

    Output:

    a0
    a1
    b0
    b1
    c0
    c1
    

    You can use this for cartesian product required in regex matching.

提交回复
热议问题