The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Use A Variable In A JavaScript Regular Expression

TODO: Pull subtitle into page object

** TL;DR

Create a new `RegExp` object to use a variable in a regex pattern match. For example:

code_start_default_section code_end_default_section
Results
the slow dog

#+NOTES:

- The example only shows one replacement but every instance of `quick` in the `source` string would be replace with `slow` due to the use of `.replaceAll` and the `g` flat which sets things to work globally

- The example uses `i` to make the match case insensitive

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Use A Variable In A JavaScript Regular Expression

-- p

** TL;DR

-- p

Create a new `RegExp` object to use a variable in a regex pattern match. For example:

-- code/
-- js

const target = 'quick'
const pattern = new RegExp(target, 'gi')


const source = 'the Quick dog'
const updated = source.replaceAll(pattern, 'slow')

console.log(updated)

-- /code

-- results/

the slow dog

-- /results

-- p

#+NOTES:

-- p

- The example only shows one replacement but every instance of `quick` in the `source` string would be replace with `slow` due to the use of `.replaceAll` and the `g` flat which sets things to work globally

-- p

- The example uses `i` to make the match case insensitive


-- categories
-- JavaScript 

-- metadata
-- date: 2022-10-21 21:55:58
-- id: 2gtdcowb
-- status: published 
-- type: post
-- SCRUBBED_NEO: false
-- site: aws