-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.html
189 lines (170 loc) · 7.21 KB
/
start.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>UrlRegex</title>
<style type="text/css">
html,body{
color: black;
}
body{
background-color: white;
font: 14px helvetica,arial,freesans,clean,sans-serif;
*font-size: small;
}
.test-set {
border: 1px solid black;
margin: 5px;
}
.test-set div{
padding: 5px;
}
.test-wrapper {
background-color: #DDD;
font-weight: bold;
}
span {
font-weight: normal;
font-style: italics;
}
.failure {
background-color: red;
}
#successes{
color: green;
font-weight: bold;
}
#failures{
color: red;
font-weight: bold;
}
textarea {
display: block;
width: 100%;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script type="text/javascript">
// This is the money right here. This is the line you want to copy.
var urlReg = /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/ig;
// Tests -- each test case is an array part of [example, expected]
var urlTests = [
['http://www.RegExr.com',
'http://www.RegExr.com'],
['http://RegExr.com',
'http://RegExr.com'],
['http://www.RegExr.com?2rjl6',
'http://www.RegExr.com?2rjl6'],
['http://www.RegExr.com?2rjl6&x=99&498',
'http://www.RegExr.com?2rjl6&x=99&498'],
['http://www.RegExr.com?2rjl6(v85)&x=99&498',
'http://www.RegExr.com?2rjl6(v85)&x=99&498'],
['http://RegExr.com#foo',
'http://RegExr.com#foo'],
['http://RegExr.com#foo(bar)',
'http://RegExr.com#foo(bar)'],
['This is my website (http://www.microsoft.com)',
'http://www.microsoft.com'],
['This is my website [http://www.microsoft.com]',
'http://www.microsoft.com'],
['http://foo.com/blah_blah',
'http://foo.com/blah_blah'],
['http://foo.com/blah_blah/',
'http://foo.com/blah_blah/'],
['(Something like http://foo.com/blah_blah)',
'http://foo.com/blah_blah'],
['http://foo.com/blah_blah_(wikipedia)',
'http://foo.com/blah_blah_(wikipedia)'],
['http://foo.com/more_(than)_one_(parens)',
'http://foo.com/more_(than)_one_(parens)'],
['(Something like http://foo.com/blah_blah_(wikipedia))',
'http://foo.com/blah_blah_(wikipedia)'],
['http://foo.com/blah_(wikipedia)#cite-1',
'http://foo.com/blah_(wikipedia)#cite-1'],
['http://foo.com/blah_(wikipedia)_blah#cite-1',
'http://foo.com/blah_(wikipedia)_blah#cite-1'],
['http://foo.com/unicode_(✪)_in_parens',
'http://foo.com/unicode_(✪)_in_parens'],
['http://foo.com/(something)?after=parens',
'http://foo.com/(something)?after=parens'],
['http://foo.com/blah_blah.',
'http://foo.com/blah_blah'],
['http://foo.com/blah_blah/.',
'http://foo.com/blah_blah/'],
['<http://foo.com/blah_blah>',
'http://foo.com/blah_blah'],
['<http://foo.com/blah_blah/>',
'http://foo.com/blah_blah/'],
['http://foo.com/blah_blah,',
'http://foo.com/blah_blah'],
['http://www.extinguishedscholar.com/wpglob/?p=364.',
'http://www.extinguishedscholar.com/wpglob/?p=364'],
['http://✪df.ws/1234',
'http://✪df.ws/1234'],
['rdar://1234',
'rdar://1234'],
['rdar:/1234',
'rdar:/1234'],
['x-yojimbo-item://6303E4C1-6A6E-45A6-AB9D-3A908F59AE0E',
'x-yojimbo-item://6303E4C1-6A6E-45A6-AB9D-3A908F59AE0E'],
['message://%[email protected]%3e',
'message://%[email protected]%3e'],
['http://➡.ws/䨹',
'http://➡.ws/䨹'],
['www.c.ws/䨹',
'www.c.ws/䨹'],
['<tag>http://example.com</tag>',
'http://example.com'],
['Just a www.example.com link.',
'www.example.com'],
['http://example.com/something?with,commas,in,url, but not at end',
'http://example.com/something?with,commas,in,url'],
['What about <mailto:[email protected]?subject=TEST> (including brokets).',
'mailto:[email protected]?subject=TEST'],
['mailto:[email protected]',
'mailto:[email protected]'],
['bit.ly/foo',
'bit.ly/foo'],
['“is.gd/foo/”',
'is.gd/foo/'],
['WWW.EXAMPLE.COM',
'WWW.EXAMPLE.COM'],
['http://www.asianewsphoto.com/(S(neugxif4twuizg551ywh3f55))/Web_ENG/View_DetailPhoto.aspx?PicId=752',
'http://www.asianewsphoto.com/(S(neugxif4twuizg551ywh3f55))/Web_ENG/View_DetailPhoto.aspx?PicId=752'],
['http://www.asianewsphoto.com/(S(neugxif4twuizg551ywh3f55))',
'http://www.asianewsphoto.com/(S(neugxif4twuizg551ywh3f55))'],
['http://lcweb2.loc.gov/cgi-bin/query/h?pp/horyd:@field(NUMBER+@band(thc+5a46634))',
'http://lcweb2.loc.gov/cgi-bin/query/h?pp/horyd:@field(NUMBER+@band(thc+5a46634))'],
['https://some.logstash-url.com/#/doc/logstash-*/logstash-2015.11.09/eventlog?id=AVDthjgPPwD8moz0X0gd&_g=()',
'https://some.logstash-url.com/#/doc/logstash-*/logstash-2015.11.09/eventlog?id=AVDthjgPPwD8moz0X0gd&_g=()']
];
$(document).ready(function(){
$.each(urlTests, function () { testUrl(this[0], this[1]); });
$("#regextext").val(urlReg.source);
$("#successes").text( $(".match:not(.failure)").length );
$("#failures").text( $(".match.failure").length );
});
function testUrl(testText, expected) {
urlReg.lastIndex = 0;
var regexMatch = urlReg.exec(testText);
if (regexMatch != null) {
regexMatch = regexMatch[0];
}
var div = $('<div class="test-set"><div class="test-wrapper">Test: <span class="test"></span></div><div class="match-wrapper">Match: <span class="match"></span></div></div>');
$(".test", div).text(testText);
$(".match", div).text(regexMatch);
if( regexMatch != expected ){
$(".match", div).addClass("failure");
}
div.appendTo($("body"));
}
</script>
</head>
<body>
<h1>Test Cases</h1>
The regex:
<textarea id="regextext" readonly="true"></textarea>
<h2>Successes: <span id="successes">0</span> Failures: <span id="failures">0</span></h2>
</body>
</html>