const regex = /(\*\*NOTE\*\*: )_([^_]*)_\n/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(\\*\\*NOTE\\*\\*: )_([^_]*)_\\n', 'gm')
const str = `JavaScript run in the browser has one set of rules when run in a
browser, and another set when run outside a browser. If you are using
JavaScript primarily to write client side scripts meant to be run in a
browser, then it is best to learn JavaScript, and develop JavaScript,
under that scenario. It is true that there are legitimate and important
ways to run JavaScript from outside the browser. For instance, you can
run JavaScript from the command prompt, or directly from inside some
IDEs. At first, however, such stratagems can lead to much confusion. As
a result, I suggest that you begin by developing JavaScript inside a
browser.
**NOTE**: _I should probably qualify what I say above. The basic syntax
of the language does not change when you switch from a browser to some
environment. (The only exception, of course, is when a browser has a
buggy implementation of JavaScript, and that still happens quite
frequently.) But even when everything works correctly, certain key
features of the language, such as the **this** keyword, have a
different significance inside a browser and outside a browser. Also, key
elements of the API, such as the **alert** function, are available in a
browser and not outside a browser. These and other differences become
manageable when you gain proficiency in the language, but at first, it
is best to avoid such subtle pitfalls by running JavaScript in the
environment in which you intend to use it. Of course, if you are
intending to write mostly server side JavaScript with **nodejs**, then
this advice is less convincing. I don't not think there are serious
disadvantages to learning JavaScript in a browser even if you want to
use it on the server side, but you will find that there are differences.
In general, I think it is easier to move from the browser to **nodejs**,
than it is to move from **nodejs** to the quirky world of browsers._
It turns out that the code you saw in the previous section provides a
good framework for beginning and intermediate level JavaScript
programmers who want to learn more about the langauge. Start out by
opening up code similar to what you see in Listing 3 and 4. As a matter
of fact, you can simply reuse VerySimple.html over and over again. As we
explore the JavaScript language, all you need do is change the name of
the JavaScript file that you are linking in. For instance, linking
VerySimple01.js for one program, then VerySimple02.js for the next
program. Better yet, follow best practices and rename each JavaScript
file to reflect its contents. For instance, ExploringLoops.js would be a
good name for a JavaScript file that you created when you wanted to
learn about how loops are written in JavaScript.`;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions