JSFiddle - React, Tailwind, and code Playground

by bobbyrne01

JavaScript

/*
 * original version
 */
var preferredCurrency = 'USD';
var regExp = /price_preferredCurrency(.*)/;
var matches = regExp.exec('/something/price_USDsometextiwant');

if (matches != null) {
  console.log(matches[1]); // sometextiwant
} else {
  console.log('was null');
}

/*
 * trying new RegExp
 */
var preferredCurrency = 'USD';
var re = new RegExp('/price_' + preferredCurrency + '(.*)/');
var matches = re.exec('/something/price_USDsometextiwant');

if (matches != null) {
  console.log(matches[1]); // sometextiwant
} else {
  console.log('was null');
}