Create regex from glob expression

后端 未结 6 398
梦如初夏
梦如初夏 2020-12-03 10:28

i write program that parse text with regular expression. Regular expression should be obtained from user. I deside to use glob syntax for user input, and convert glob string

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 11:02

    jPaq's RegExp.fromWildExp function does something similar to this. The following is taken from the example that is on the front page of the site:

    // Find a first substring that starts with a capital "C" and ends with a
    // lower case "n".
    alert("Where in the world is Carmen Sandiego?".findPattern("C*n"));
    
    // Finds two words (first name and last name), flips their order, and places
    // a comma between them.
    alert("Christopher West".replacePattern("(<*>) (<*>)", "p", "$2, $1"));
    
    // Finds the first number that is at least three numbers long.
    alert("2 to the 64th is 18446744073709551616.".findPattern("#{3,}", "ol"));
    

提交回复
热议问题