JSFiddle - React, Tailwind, and code Playground
by jun68ykt
HTML
<script src="https://getfirebug.com/firebug-lite-debug.js"></script>
JavaScript
// 変換対象の正規表現
const regex = /number=\d+(,\d+)*/;
// 変換される例1
var str = 'index.htm?id=01&name=john&number=11,21,32&class=01';
var result = str.replace(regex, 'number=01');
console.log(result); // => index.htm?id=01&name=john&number=01&class=01
// 変換される例2
str = 'index.htm?id=01&name=john&number=11&class=01';
result = str.replace(regex, 'number=01');
console.log(result); // => index.htm?id=01&name=john&number=01&class=01
// 変換されない例
str = 'index.htm?id=01&name=john&number=AA,BB,CC&class=01';
result = str.replace(regex, 'number=01');
console.log(result); // => index.htm?id=01&name=john&number=AA,BB,CC&class=01