You can use a string as a regular expression using the RegExp Object:

var myPattern = new RegExp('.'+myWord,'g'); 

Fiddle Example

Doing a single match in your case, is simply changed the second parameter in RegExp from g to m (which means to make one match per line for multi lines, but in this case a strings is simply all one line). For finding the word "wood" from "ood","od","d", or other cases. You can do this:

var myPattern = new RegExp("\\b\\w+"+myWord+"\\b",'m'); 

Note I have a solution in the comments below, but this one is better.

The items \\b ... \\b mean word boundaries. Basically ensuring that it matches a single word. Then the \\w means any valid "word character". So overall the regexp means (using myWord = "od"):

|word boundary| + (1 or more word characters) + "od" + |word boundary|

This will ensure that it matches any words in the string than end with the characters "od". Or in a more general case you can do:

var myPattern = new RegExp("\\b\\w*"+myWord+"\\w*\\b",'m'); 
Answer from Spencer Wieczorek on Stack Overflow
🌐
W3Schools
w3schools.com › jsref › jsref_match.asp
JavaScript String match() Method
cssText getPropertyPriority() getPropertyValue() item() length parentRule removeProperty() setProperty() JS Conversion · ❮ Previous JavaScript String Reference Next ❯ · A search for "ain" using a string: let text = "The rain in SPAIN stays mainly in the plain"; text.match("ain"); Try it Yourself » ·
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › match
String.prototype.match() - JavaScript | MDN
'Chapter 3.4.5.1' was captured by (chapter \d+(\.\d)*). '.1' was the last value captured by (\.\d). The index property (22) is the zero-based index of the whole match. The input property is the original string that was parsed. The following example demonstrates the use of the global flag and ignore-case flag with match(). All letters A through E and a through e are returned, each its own element in the array. js ·
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-string-match-method
JavaScript String match() Method - GeeksforGeeks
July 11, 2025 - The global (g) flag ensures that all occurrences of the matching pattern are returned. Below is an example that matches the substring "eek" multiple times in the string:
🌐
DigitalOcean
digitalocean.com › community › tutorials › js-string-match
A Quick Guide to the String Match Method in JavaScript | DigitalOcean
January 7, 2020 - const str = 'See you later, Alligator! Not so soon baboon!'; const matches = str.match(/([a-z])\1+/gi); console.log('H' + matches.join("")); // "Heelloooo" Though these are simple examples, the deeper you learn about regular expressions, the more powerful this string method becomes.
🌐
TechOnTheNet
techonthenet.com › js › string_match.php
JavaScript: String match() method
You can use the match() method to search for the first occurrence of a regular expression pattern. ... In this example, we have declared a variable called totn_string that is assigned the string value of 'TechOnTheNet'. We have then invoked the match() method of the totn_string to find matches ...
🌐
CodingNomads
codingnomads.com › match-string-javascript
JavaScript String Matching
Or the one whose scope more closely matches your task. For instance, if all you want to do is to check if a string contains another substring, then you'll want to use the method in the next section. Sometimes all you are interested in is whether a string exists in another string. If so, then the .includes() method is for you. That method returns a boolean indicating whether a substring is present within a string. Here's an example:
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Regular_expressions
Regular expressions - JavaScript | MDN
For example, the pattern /abc/ matches character combinations in strings only when the exact sequence "abc" occurs (all characters together and in that order). Such a match would succeed in the strings "Hi, do you know your abc's?" and "The latest airplane designs evolved from slabcraft.".
Find elsewhere
🌐
Medium
medium.com › nerd-for-tech › basics-of-javascript-string-match-method-ce47295bfd97
Basics of Javascript · String · match() (method) | by Jakub Korch | Nerd For Tech | Medium
June 9, 2021 - If the regular expression does not include the “g” flag, we get the Array object with the result at index 0. The resulting Array object has the same format as if we invoked method exec() on regular expression passing our referenced string. The Array object contains additional data like index at which the first occurrence of match happened, original input, etc….
🌐
Programiz
programiz.com › javascript › library › string › match
Javascript String match()
groups - An object of named capturing groups having keys as the names and values as the captured matches. index - The index of search where the result was found. ... const string = "My name is Albert.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › string-match
The String `match()` Function in JavaScript - Mastering JS
The 4 digits, 2 digits, 2 digits // are capture groups. const [year, month, day] = str.match(/(\d{4})-(\d{2})-(\d{2})/).slice(1, 4); year; // '2022' month; // '06' day; // '01' Note that capture groups do not work if you specify the g flag on ...
🌐
TutorialsPoint
tutorialspoint.com › home › javascript › javascript string match
JavaScript String Match
September 1, 2008 - In the following example, we are using the JavaScript String match() method to search for the string 'h' and retrieve an array with all matches in the original string "Hi how are you?"
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › String › match
JavaScript String Match() - Match String Pattern | Vultr Docs
November 15, 2024 - Check if a string is a valid email using the match() method. ... const input = "user@example.com"; const isValidEmail = input.match(/^\w+@\w+\.\w+$/); console.log(isValidEmail ?
🌐
freeCodeCamp
freecodecamp.org › news › javascript-regex-match-example-how-to-use-the-js-replace-method-on-a-string
JavaScript Regex Match Example – How to Use JS Replace on a String
January 4, 2021 - Some of you might have already noticed this, but if you look at the example above, .match() is only matching the first occurrence of the word "are". A lot of times you'll want to know how often a pattern is matched against the string you're testing, so let's take a look at how to do that with .match().
🌐
Codecademy
codecademy.com › docs › javascript › strings › .match()
JavaScript | Strings | .match() | Codecademy
June 11, 2025 - The .match() method applies this regex to the string and returns an array of all matches: const paragraph = 'The quick brown fox jumps over the lazy dog. It barked.'; ... This example demonstrates how to use the .match() method to find all ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › RegExp › Symbol.match
RegExp.prototype[Symbol.match]() - JavaScript | MDN
class MyRegExp extends RegExp { [Symbol.match](str) { const result = RegExp.prototype[Symbol.match].call(this, str); if (!result) return null; return { group(n) { return result[n]; }, }; } } const re = new MyRegExp("(\\d+)-(\\d+)-(\\d+)"); const str = "2016-01-02"; const result = str.match(re); // String.prototype.match calls re[Symbol.match](). console.log(result.group(1)); // 2016 console.log(result.group(2)); // 01 console.log(result.group(3)); // 02 · Polyfill of RegExp.prototype[Symbol.match] in core-js
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-match-function
JavaScript String match() Function - GeeksforGeeks
November 30, 2022 - Here “g” flag indicates that ... string. ... Example 2: In this example, the substring “eek” will match with the given string, and it will return instantly if it found the match....
🌐
Jsremote
jsremote.jobs › tutorials › string-match
What is the match() method in JavaScript? | Web developer jobs
Thus, if you call match(/\d+/g), the method will return an array of all numeric substrings as illustrated in the code below. const string = '12 plus 5 is equal to 17'; const array = string.match(/\d+/g); console.log(array); // logs "(3) ['12', ...
🌐
Javatpoint
javatpoint.com › javascript-string-match-method
JavaScript String match() Method - javatpoint
JavaScript string match() Method with example, by string literal, by string object (using new keyword), javascript string methods, charAt(index) method, concat(str) method, indexOf(str) method, lastIndexOf(str) method, lowerCase() method, upperCase() method, slice(beginIndex, endIndex) method, trim() method, toLowerCase(), slice(), concat(), charCodeAt() method etc.