regexp practice

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FRegExp

by michaeldausmann

HTML

<div class="fillme">This is a box</div>

CSS

.fillme{
    background-color:#123456
}

}

JavaScript

//var re = /\[(.*?):(.*?)\]/g;

var input, re, m, output;

//* Matches the preceding item 0 or more times.... NOTE THE ZERO
input = 'a bird warbled'
re = /bo*/;
m = re.exec(input);
console.log('1. ' + JSON.stringify(m));

//*? Matches like * and + from above, however the match is the smallest possible match.
input = '"foo" "bar"'
re = /".*?"/;
m = re.exec(input);
console.log('2. ' + JSON.stringify(m));

input = '"foo" "bar"'
re = /".*"/;
m = re.exec(input);
console.log('3. ' + JSON.stringify(m));

input = "foo bar. Eat Food";
re = /(foo.)/;
m = re.exec(input);
console.log('4.1. ' + JSON.stringify(m));
m2 = re.exec(input);
console.log('4.2. ' + JSON.stringify(m2));

input = "foo bar. Eat Food";
re = /(?:foo.)/;
m = re.exec(input);
console.log('5. ' + JSON.stringify(m));

//from http://callumacrae.github.io/regex-tuesday/challenge1.html
input = "<Mack> I'll I'll be be back back in in a a bit bit.";
re = /\b([^\s]+)\s+(\1)\b/ig;
output = input.replace(re, "$1 <strong>$2</strong>");
console.log('6. ' + output);

//from http://callumacrae.github.io/regex-tuesday/challenge1.html
input = "<Mack> I'll I'll be be back back in in a a bit bit.";
re = /^#(?:[0-9a-fA-F]{1,2}){3}$/;
output = input.replace(re, "$1 <strong>$2</strong>");
console.log('7. ' + output);