参考:
https://qiita.com/iLLviA/items/b6bf680cd2408edd050f
i 大文字小文字区別しない
g すべてのものを検索
m 複数行検索
[abc] []内のものを検索
[0-9] 0-9の数字を検索
<body>
<p id="test"></p>
<button onclick="testReplace()">click me</button>
<script>
var stringTest = "tomorrow will be good";
// 大文字小文字区別しないで検索
var goodIndex = stringTest.search(/Good/i);
var pTest = document.getElementById("test");
pTest.innerHTML = "Goodのインデックスは" + goodIndex;
function testReplace(){
var newString = stringTest.replace(/tomorrow/i,"明日");
pTest.innerHTML = newString;
}
</script>
</body>
More than 1 year has passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme