Sunday, January 21, 2018

regex

var str = "/* First comment */\n/* another comment */";
var patt1 = /\/\*[\s\S]*?\*\//mg;
var result = str.match(patt1);
console.log("result is: " + result);
var patt2 = /([^:"'=])/g;
var str2 = "p:\"Hi\"...'Hi' x=y";
console.log(str2 + "->" + str2.match(patt2));
var  jsSuffixRegExp = /\.js$/;
console.log("app.js".replace(jsSuffixRegExp, ''));
Output:
result is: /* First comment */,/* another comment */
p:"Hi"...'Hi' x=y->p,H,i,.,.,.,H,i, ,x,y
app

No comments:

Post a Comment