-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
196 lines (160 loc) · 5.53 KB
/
index.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="description" content="RegexWorkbench.js is an online open source tool and tester for regular expressions based on javascript. Features are Highlighting, Replace, Ignore Cases, Multiline and a human readable output. [ MIT License ]" />
<meta name="keywords" content="regex, workbench, regular, expression, regex, regexp, online, tool, tester, editor, javascript" />
<title>RegexWorkbench.js</title>
<link rel="stylesheet" type="text/css" href="css/main.css" />
<link rel="stylesheet" type="text/css" href="css/regex-colorizer.css" />
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/regex-colorizer.js"></script>
<script type="text/javascript">
$(function(){
/// Auto-Run
chooseFunction();
/// Events
$("#regexPattern").on('input', chooseFunction);
$("#regexReplace").on('input', chooseFunction);
$("#regexInput").on('input', chooseFunction);
$("#optionMultiline").on("click", chooseFunction);
$("#optionIgnoreCase").on("click", chooseFunction);
$("#forceRefresh").on("click", chooseFunction);
$("#regexPattern").focusout(function(){
addPaternStyle();
if($("#regexPattern").html() == "undefined") {
$("#regexPattern").html("");
}
});
$("#optionReplace").on("click", function() {
if(isReplace){
isReplace = false;
}
else {
isReplace = true;
}
chooseFunction();
});
/// Functions
// regex-colorizer
function addPaternStyle() {
RegexColorizer.addStyleSheet();
RegexColorizer.colorizeAll();
}
function chooseFunction() {
// Modifiers
var modifiers = "g";
if( $('#optionMultiline').prop('checked') )
modifiers += "m";
if( $('#optionIgnoreCase').prop('checked') )
modifiers += "i";
// Start function
if( $("#optionReplace").is(':checked') ) {
updateReplace(modifiers);
}
else {
updateMatches(modifiers);
}
}
function updateReplace(modifiers) {
var regexPattern = unescape(encodeURIComponent( $("#regexPattern").text() ));
var regexReplace = unescape(encodeURIComponent( $("#regexReplace").val() ));
var regexInput = unescape(encodeURIComponent( $("#regexInput").val() ));
var replaceOutput = RWreplace(regexPattern, regexReplace, regexInput, modifiers);
try {
$('#regexOutput').val( decodeURIComponent(escape( replaceOutput )) );
}
catch (e) {
// Error
}
}
function updateMatches(modifiers) {
$("#regexOutput").val("");
var regexPattern = unescape(encodeURIComponent( $("#regexPattern").text() ));
var regexInput = unescape(encodeURIComponent( $("#regexInput").val() ));
var matchArray = RWmatch(regexPattern, regexInput, modifiers);
var regexOutput = "";
try {
var i = 0;
while( i < matchArray.length){
if(matchArray[i] != undefined) {
regexOutput = regexOutput + decodeURIComponent(escape( matchArray[i] )) + "\n";
}
i++;
}
$('#regexOutput').val(regexOutput);
// Number of matches
if(matchArray[0] == ""){
$("#numberOfMatches").html(0);
}
else {
$("#numberOfMatches").html(i);
}
} catch (e) {
// regexInput is empty
}
}
function RWmatch(regexPattern, regexInput, modifiers) {
if(regexPattern != "" && regexInput != ""){
try {
var pattern = RegExp(regexPattern, modifiers);
} catch (e) {
// Error: Not a regular expression
}
var matchArray = new Array();
match = pattern.exec(regexInput);
for (var i = 0; match != null; i++) {
matchArray[i] = match[1];
for(var j = 2; j <= match.length-1; j++){
matchArray[i] = matchArray[i] + "," + match[j];
}
match = pattern.exec(regexInput);
if(i > 1000000) {
alert("Stopped operation => Over 1 million data sets.");
break;
}
}
return matchArray;
}
}
function RWreplace(regexPattern, regexReplace, regexInput, modifiers) {
try {
var pattern = RegExp(regexPattern, modifiers);
} catch (e) {
// Error: Not a regular expression
}
return regexInput.replace(pattern, regexReplace);
}
});
</script>
</head>
<body>
Regular Expression Pattern:<br />
<div id="regexPattern" class="regex" contenteditable=""></div>
<button id="forceRefresh">Force refresh</button>
<br />
Options:<br />
<input type="checkbox" id="optionReplace">Replace <input type="checkbox" id="optionMultiline">Multiline <input type="checkbox" id="optionIgnoreCase">Ignore Case
<br />
<br />
Replace String:
<input type="text" id="regexReplace" />
<br />
<br />
Search String:<br />
<textarea id="regexInput"></textarea>
<br />
<br />
Output String:<br />
<textarea id="regexOutput" readonly="readonly"></textarea>
<br />
<br />
Matches: <span id="numberOfMatches">0</span>
<br />
<br />
<center>
RegexWorkbench.js is a editor for regular expressions based on javascript. Features are Highlighting, Replace, Ignore Cases, Multiline and a human readable output. [ MIT License ]<br />
<a href="https://github.com/Staubteufel/RegexWorkbench.js">Fork me on Github</a>
</center>
</body>
</html>