const regex = /[^ -~]/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('[^ -~]', 'gm')
const str = ` Punctuation marks are standardized marks or signs used to clarify the meaning and separate structural units of text. The General Category property assigns characters to either Punctuation or Symbol based on their primary usage.
Q: Can you give a more complete list of Unicode punctuation characters that often should be treated as symbols?
A: Because this issue is about conflicting usage, it is not possible to generate a comprehensive list, however some of the most common ones are:
U+0023 ( # ) NUMBER SIGN
U+0026 ( & ) AMPERSAND
U+0040 ( @ ) COMMERCIAL AT
U+0025 ( % ) PERCENT SIGN
U+2030 ( ‰ ) PER MILLE SIGN
U+2031 ( ‱ ) PER TEN THOUSAND SIGN
U+002A ( * ) ASTERISK
U+2020 ( † ) DAGGER
U+2021 ( ‡ ) DOUBLE DAGGER
U+203B ( ※ ) REFERENCE MARK
Łąka
Русский
维基百科,自由的百科全书`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
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