-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegex-Tester.html
More file actions
122 lines (103 loc) · 2.73 KB
/
Copy pathRegex-Tester.html
File metadata and controls
122 lines (103 loc) · 2.73 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Regex Tester</title>
<link rel="icon" href="favicon.png">
<style>
body {
font-family: Arial, sans-serif;
background: #f1f9ff;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
}
.container {
background: #fff;
padding: 20px;
border-radius: 12px;
box-shadow: 0 0 10px rgba(0,0,0,0.05);
width: 90%;
max-width: 600px;
}
h2 {
color: #007bff;
text-align: center;
margin-bottom: 20px;
}
input, .input-box {
width: 100%;
padding: 10px;
font-size: 16px;
margin: 10px 0;
border-radius: 8px;
border: 1px solid #ccc;
box-sizing: border-box;
}
.input-box {
min-height: 100px;
background: #f9f9f9;
white-space: pre-wrap;
overflow-y: auto;
}
button {
padding: 10px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 8px;
font-size: 16px;
cursor: pointer;
margin-top: 10px;
}
button:hover {
background-color: #0056b3;
}
#result {
margin-top: 15px;
background: #e7f9e9;
padding: 10px;
border-radius: 8px;
font-size: 16px;
white-space: pre-wrap;
color: #333;
}
</style>
</head>
<body>
<div class="container">
<h2>Regex Tester</h2>
<input type="text" id="regexInput" placeholder="Enter regular expression (e.g. \\d+)" />
<div class="input-box" id="textInput" contenteditable="true" placeholder="Enter test string here..."></div>
<button onclick="testRegex()">Test Regex</button>
<div id="result"></div>
</div>
<script>
function testRegex() {
const pattern = document.getElementById("regexInput").value;
const text = document.getElementById("textInput").innerText;
const resultDiv = document.getElementById("result");
try {
const regex = new RegExp(pattern, 'g');
const matches = [...text.matchAll(regex)];
if (matches.length > 0) {
let output = "Matches found:\n";
matches.forEach((match, index) => {
output += `${index + 1}: ${match[0]}\n`;
});
resultDiv.style.background = "#e7f9e9";
resultDiv.textContent = output;
} else {
resultDiv.style.background = "#fff3cd";
resultDiv.textContent = "No matches found.";
}
} catch (e) {
resultDiv.style.background = "#f8d7da";
resultDiv.textContent = "Invalid regular expression!";
}
}
</script>
</body>
</html>