LoginSignup
1
1

More than 1 year has passed since last update.

javaScript_正規表現,search,replaceメソッドなど

Posted at
参考:
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>

1
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1