4 ms·
If you have Chrome dev tools open, you can go to the console and define a variable that holds your text using an ES6 string template, like so: var text = `H
by stygiansonic 11y ago
If you have Chrome dev tools open, you can go to the console and define a variable that holds your text using an ES6 string template, like so:
var text = `Hello World:
Here is a multiline
piece of text`
I would then follow this guide on JavaScript regex:
https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/R...
Here's a short example/sample, based on the text above: (You should be able to copy-paste this directly into the console as well, following the declaration of `text` above)
// Logs the lines to console that match a certain regex.
// This is a very poor approximation of grep.
var re = /(Hello|text)/g
text.split("\n").forEach(function(line) {
if (line.match(re)) {
console.log(line);
}
});
Using the JavaScript console of your browser is a great way to learn the language, prototype ideas and sometimes to debug into your webapp. (Sometimes it feels like hotswap when using the JVM :))