-
Notifications
You must be signed in to change notification settings - Fork 0
/
regex.html
69 lines (69 loc) · 1.86 KB
/
regex.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<html>
<head>
<style type="text/css">
textarea {
width: 900px;
height: 400px;
}
input {
width: 300px;
margin: 5px 0;
}
#container {
width: 900px;
margin-left: auto;
margin-right: auto;
}
#middle {
text-align: center;
}
</style>
</head>
<body>
<div id="container">
<h1>Regular Expression Replacer</h1>
<p>
Put the text you'd like to replace in the first text box, the
<a href="http://developer.mozilla.org/en/JavaScript/Guide/Regular_Expressions">Regular Expression</a>
and replacement text, and click "Replace All" and then the replaced text
will be placed in the bottom text box.
</p>
<div>
<textarea id="from" placeholder="Text to Replace"></textarea>
</div>
<div id="middle">
<div>
<input placeholder="Regular Expression (eg: (\s+)replace-me )" id="regex" />
</div>
<div>
<input placeholder="Replace With (eg: $1replaced-text )" id="replace" />
</div>
<div>
<button id="go">Replace All</button>
</div>
</div>
<div>
<textarea id="output" placeholder="Result"></textarea>
</div>
</div>
<a href="https://github.com/maxrabin/regex"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" /></a>
<script>
(function () {
var button = document.getElementById('go')
, regex = document.getElementById('regex')
, replace = document.getElementById('replace')
, from = document.getElementById('from')
, output = document.getElementById('output')
;
button.addEventListener('click', function () {
var regexObj = new RegExp(regex.value, 'g')
, inputStr = from.value
, outputStr
;
outputStr = inputStr.replace(regexObj, replace.value);
output.value = outputStr;
});
})()
</script>
</body>
<html>