index.html 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <meta charset="utf-8" />
  4. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  5. <title>Regex Tester</title>
  6. <script>
  7. function substitute() {
  8. pattern = document.getElementById('pattern').value;
  9. text = document.getElementById('text').value;
  10. prefix = document.getElementById('prefix').value;
  11. repl = document.getElementById('repl').value;
  12. suffix = document.getElementById('suffix').value;
  13. exp = new RegExp(pattern, 'g');
  14. result = prefix + text.replace(exp, repl) + suffix
  15. document.getElementById('result').value = result
  16. return false;
  17. }
  18. function copy() {
  19. document.getElementById('result').select();
  20. document.execCommand('copy');
  21. }
  22. </script>
  23. <form onsubmit="return substitute()">
  24. <p>pattern <input id="pattern" value="[\.,]\s+"></p>
  25. <p>text <input id="text"></p>
  26. <p>prefix <input id="prefix" value="<ul><li>"></p>
  27. <p>repl <input id="repl" value="</li><li>"></p>
  28. <p>suffix <input id="suffix" value="</li></ul>"></p>
  29. <p><input type="submit" value="substitute"></p>
  30. </form>
  31. <p>
  32. <textarea id="result"></textarea>
  33. <br>
  34. <input type="button" onclick="copy()" value="copy">
  35. </p>
  36. </html>