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.

Find and Replace with String or RegEx

TODO: Pull subtitle into page object

The simplest replacement is substituting one string for another with `.replace()`

code_start_default_section code_end_default_section
Results
There are lots and lots of corgis

More here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace

Debugging Stuff

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

        -- title

Find and Replace with String or RegEx

-- p

The simplest replacement is substituting one
string for another with `.replace()`

-- code/
-- js

const original = "the quick brown fox"

const updated = original.replaceAll('brown', 'green')

console.log(updated)

-- /code

-- results/

the quick green fox

-- /results

-- p

This can also be done with a regular expression

-- p

TODO: See also: `.replace()` which only does one

-- p

This is an example using a regex.
You can also use a string.
TKTKTK make more examples including ones with functions and strings

-- code/
-- js

const regex = /\d+s/g

const original = "There are 1000s and 1000s of corgis"

const updated = original.replace(regex, 'lots')

console.log(updated)

-- /code

-- results/

There are lots and lots of corgis

-- /results

-- p

More here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace


-- categories
-- JavaScript

-- metadata
-- date: 2022-01-06 22:02:20
-- id: 23ls8ilw
-- status: scratch
-- type: post 
-- SCRUBBED_NEO: false
-- site: aws