Regex pattern for Pilcrow (¶) or Partial Differential (∂) character
The correct Unicode code points are U+00B6 and U+2202, not U+2029. You'll also want to use a [] character range in your expression:
const value = 'Javascript Regex pattern for Pilcrow (¶) or Partial Differential (∂) character';
const matches = value.match(/[\u00B6\u2202]/gmi);
console.log(matches);
Of course, you don't really need \u escapes in the first place:
const value = 'Javascript Regex pattern for Pilcrow (¶) or Partial Differential (∂) character';
const matches = value.match(/[¶∂]/gmi);
console.log(matches);
Last but not least, you say:
they currently show as �.
If that's the case, it's very likely that it isn't properly encoded to begin with. In other words, you won't find ¶
or ∂
because they aren't there. I suggest you address this first.
Use String.prototype.codePointAt
to extract the unicode UTF-16 code point and convert it into hex digits sequence.
const toUnicodeCodePointHex = (str) => {
const codePoint = str.codePointAt(0).toString(16);
return '\\u' + '0000'.substring(0, 4 - codePoint.length) + codePoint;
};
const value = 'Javascript Regex pattern for Pilcrow (¶) or Partial Differential (∂) character';
const re = new RegExp(['¶', '∂'].map((item) => toUnicodeCodePointHex(item)).join('|'), 'ig');
const matches = value.match(re);
console.log(matches);
See this very nice article
by Mathias Bynens.