Function escapeLiteralStringForRegex

escape a string so that it can be matched exactly in a regex constructor.

import { assertEquals as assertEq } from "jsr:@std/assert"

const
substring = String.raw`(\|[++h.e.\\.o++]|/)`,
substring_escaped = escapeLiteralStringForRegex(substring),
my_regex = new RegExp(`${substring_escaped}\\(world\\)`),
my_string = String.raw`this string consist of (\|[++h.e.\\.o++]|/)(world) positioned somewhere in the middle`

assertEq(my_regex.test(my_string), true)