Skip to main content

escapeRegex

Escape a string so it can be safely embedded into a RegExp source.
s
string
Any string
Returns: string - Escaped string safe for use in regular expressions.
escapeRegex("Hello (world)"); // "Hello \\(world\\)"
escapeRegex("$100.50"); // "\\$100\\.50"

makeDiacriticInsensitiveRegex

Build a diacritic-insensitive, tatweel-tolerant RegExp for Arabic text matching. Features:
  • Optional character equivalences: اأإآ, ةه, ى~ي
  • Optional tolerance for tatweel between characters
  • Optional diacritic-insensitivity (by inserting a diacritics class after each char)
  • Optional flexible whitespace (needle whitespace becomes \s+)
needle
string
required
The Arabic text to match
opts
MakeRegexOptions
Configuration options for the regex pattern

MakeRegexOptions

equivalences
EquivOptions
Character equivalences to allow. Default: { alif: true, taMarbutahHa: true, alifMaqsurahYa: true }
  • alif (boolean): Treat ا/أ/إ/آ as equivalent. Default: true
  • taMarbutahHa (boolean): Treat ة/ه as equivalent. Default: true
  • alifMaqsurahYa (boolean): Treat ى/ي as equivalent. Default: true
allowTatweel
boolean
default:"true"
Allow tatweel between letters (tolerate decorative elongation)
ignoreDiacritics
boolean
default:"true"
Ignore diacritics by inserting a DIACRITICS_CLASS* after each letter
flexWhitespace
boolean
default:"true"
Treat any whitespace in the needle as \s+ for flexible matching
flags
string
default:"'u'"
RegExp flags to use
Returns: RegExp - A RegExp matching the needle with the desired tolerances.
const rx = makeDiacriticInsensitiveRegex('أنا إلى الآفاق');
rx.test('انا الي الافاق'); // true
rx.test('اَنا إلى الآفاق'); // true

// Custom options
const strictRx = makeDiacriticInsensitiveRegex('أنا', {
  equivalences: { alif: false, taMarbutahHa: false, alifMaqsurahYa: false },
  ignoreDiacritics: false,
  allowTatweel: false
});

removeAllTags

Remove simple HTML/XML-like tags from a string. This is intentionally lightweight and does not attempt to parse HTML; it simply drops substrings that look like <...>.
content
string
Input string
Returns: string - String with tags removed.
removeAllTags("<p>Hello <strong>world</strong></p>"); // "Hello world"
removeAllTags("<div>Text</div>"); // "Text"

Build docs developers (and LLMs) love