Skip to content

Commit d78bdfb

Browse files
committed
minimum viable version
1 parent 2b5c4a8 commit d78bdfb

File tree

1 file changed

+74
-4
lines changed

1 file changed

+74
-4
lines changed

regexplanet.rb

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@
5050
output << h(params[:replacement])
5151
output << "</td>\n"
5252

53+
options = 0
54+
str_options = request_params_multi(request.query_string)["option"]
55+
if str_options
56+
if str_options.include?("comment")
57+
options += Regexp::EXTENDED
58+
end
59+
if str_options.include?("dotall")
60+
options += Regexp::MULTILINE
61+
end
62+
if str_options.include?("ignorecase")
63+
options += Regexp::IGNORECASE
64+
end
65+
end
66+
67+
regex = Regexp.new(str_regex, options)
5368
# when ruby 1.9
5469
#if Regexp.try_convert(str_regex)
5570
# output << "\t<tr>\n"
@@ -64,9 +79,47 @@
6479
# } )
6580
#end
6681

67-
regex = Regexp.new(str_regex)
82+
if regex
83+
output << "\t<tr>\n"
84+
output << "\t\t<td>Options</td>\n"
85+
output << "\t\t<td>"
86+
output << regex.options.to_s
87+
output << "</td>\n"
88+
output << "\t</tr>\n"
6889

69-
output << "\t</tr>\n"
90+
if regex.options != 0
91+
output << "\t<tr>\n"
92+
output << "\t\t<td>Options as constants</td>\n"
93+
output << "\t\t<td>"
94+
if (regex.options & Regexp::IGNORECASE) != 0
95+
output << "Regexp::IGNORECASE "
96+
end
97+
if (regex.options & Regexp::EXTENDED) != 0
98+
output << "Regexp::EXTENDED "
99+
end
100+
if (regex.options & Regexp::MULTILINE) != 0
101+
output << "Regexp::MULTILINE "
102+
end
103+
#if (regex.options & Regexp::FIXEDENCODING) != 0
104+
# output << "Regexp::FIXEDENCODING "
105+
#end
106+
#if (regex.options & Regexp::NOENCODING) != 0
107+
# output << "Regexp::NOENCODING "
108+
#end
109+
output << "</td>\n"
110+
output << "\t</tr>\n"
111+
end
112+
113+
#names = regex.names
114+
#if names
115+
# output << "\t<tr>\n"
116+
# output << "\t\t<td>Named captures (names)</td>\n"
117+
# output << "\t\t<td>"
118+
# output << h(names.to_s)
119+
# output << "</td>\n"
120+
#end
121+
122+
end
70123

71124
output << "</table>\n"
72125

@@ -75,6 +128,7 @@
75128
output << "\t<tr>\n"
76129
output << "\t\t<th style=\"text-align:center;\">Test</th>\n"
77130
output << "\t\t<th>Input</th>"
131+
output << "\t\t<th>=~</th>"
78132
output << "\t\t<th>match()</th>"
79133
output << "\t</tr>\n"
80134

@@ -104,6 +158,16 @@
104158
output << "\t\t<td>"
105159
output << h(input)
106160
output << "</td>\n"
161+
162+
output << "\t\t<td>"
163+
eq = regex =~ input
164+
if eq:
165+
output << h(eq.to_s)
166+
else
167+
output << "<i>nil</i>"
168+
end
169+
output << "</td>\n"
170+
107171
md = regex.match(input)
108172
if md == nil
109173
output << "\t\t<td><i>"
@@ -117,10 +181,16 @@
117181
first = false
118182
else
119183
output << "\t<tr>\n"
120-
output << "\t\t<td colspan=\"2\" style=\"text-align:right;\">regex.match(matchdata.post_match)</td>"
184+
output << "\t\t<td colspan=\"3\" style=\"text-align:right;\">regex.match(matchdata.post_match)</td>"
121185
end
122186
output << "\t\t<td>"
123-
output << h(md.inspect)
187+
for mdindex in 0..md.size-1
188+
output << "["
189+
output << mdindex.to_s
190+
output << "]: "
191+
output << h(md[mdindex])
192+
output << "<br/>"
193+
end
124194
output << "</td>\n"
125195
output << "\t</tr>\n"
126196
md = regex.match(md.post_match)

0 commit comments

Comments
 (0)