Skip to content

Instantly share code, notes, and snippets.

@coke12103
Created June 28, 2021 04:06
Show Gist options
  • Save coke12103/678c2edfb44e9819119f8ae55731614e to your computer and use it in GitHub Desktop.
Save coke12103/678c2edfb44e9819119f8ae55731614e to your computer and use it in GitHub Desktop.
置換してくれるやつ
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Replace</title>
</head>
<body>
<div style="display: flex; flex-direction: column;">
<p>input</p>
<textarea id="input" rows="10" cols= "50"></textarea>
<input type="button" onclick="main()" value="Go">
<p>output</p>
<textarea id="output" rows="10" cols= "50"></textarea>
<p>template</p>
<textarea id="template" rows="10" cols= "50"></textarea>
</div>
<script>
function main(){
let input = document.getElementById("input").value;
if(!input) return;
let split_text = input.replace(new RegExp("[a-z]", "g"), "\n").split("\n");
let template = document.getElementById("template").value;
let result = template;
split_text = split_text.filter((val) => val !== "");
for(let i = 0; i < split_text.length; i++){
result = result.replace(new RegExp(`{REP${i}}`, "g") ,split_text[i]);
}
document.getElementById("output").value = result;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment