Skip to content

Commit 9863770

Browse files
committed
Converting HTML table to markdown table
This converts the HTML table to a markdown table which allows for including links in cell whereas this does not seem to work in HTML tables. Signed-off-by: Georg Kunz <[email protected]>
1 parent 9f05d06 commit 9863770

File tree

1 file changed

+10
-93
lines changed

1 file changed

+10
-93
lines changed

docs/Correctly-Using-Regular-Expressions.md

Lines changed: 10 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -23,99 +23,16 @@ When using regexes for secure validation of untrusted input, do the following so
2323
1. If there are any branches (“&#x7c;”), make sure the alternatives are grouped. You can do this by surrounding them with parentheses like this: “(aa&#x7c;bb)”. If you don’t need the groups to be captured (you usually don’t), and your platform supports non-capturing groups (most do), it’s usually more efficient to use non-capturing groups - just change “(“ into “(?:”
2424
2. Use a regular expression in its normal mode (not “multiline” mode). Prepend a start-of-string marking (often “^” or “\A”) and append an “end-of-string” marking (often “$” or “\z”, but Python uses “\Z”). Do _not_ use “$” for input validation until you verify that “$” does what you want. See this table for many common platforms:
2525

26-
<table>
27-
<tr>
28-
<td>
29-
Platform
30-
</td>
31-
<td>Prepend
32-
</td>
33-
<td>Append
34-
</td>
35-
<td>$&nbsp;Permissive?
36-
</td>
37-
</tr>
38-
<tr>
39-
<td>POSIX BRE, POSIX ERE, and ECMAScript (JavaScript)
40-
</td>
41-
<td>“^” (not “\A”)
42-
</td>
43-
<td>“$” (not “\z” nor “\Z”)
44-
</td>
45-
<td>No
46-
</td>
47-
</tr>
48-
<tr>
49-
<td>Perl, .NET/C#
50-
</td>
51-
<td>“^” or “\A”
52-
</td>
53-
<td>“\z” (not “$”)
54-
</td>
55-
<td>Yes
56-
</td>
57-
</tr>
58-
<tr>
59-
<td>Java
60-
</td>
61-
<td>“^” or “\A”
62-
</td>
63-
<td>“\z”; [“$” works but some documents conflict](./Correctly-Using-Regular-Expressions-Rationale#java)
64-
</td>
65-
<td>No
66-
</td>
67-
</tr>
68-
<tr>
69-
<td>PHP
70-
</td>
71-
<td>“^” or “\A”
72-
</td>
73-
<td>“\z”; “$” with “D” modifier
74-
</td>
75-
<td>Yes
76-
</td>
77-
</tr>
78-
<tr>
79-
<td>PCRE
80-
</td>
81-
<td>“^” or “\A”
82-
</td>
83-
<td>“\z”; “$” with PCRE2_ DOLLAR_ENDONLY
84-
</td>
85-
<td>Yes
86-
</td>
87-
</tr>
88-
<tr>
89-
<td>Golang, Rust crate regex, and RE2
90-
</td>
91-
<td>“^” or “\A”
92-
</td>
93-
<td>“\z” or “$”
94-
</td>
95-
<td>No
96-
</td>
97-
</tr>
98-
<tr>
99-
<td>Python
100-
</td>
101-
<td>“^” or “\A”
102-
</td>
103-
<td>“\Z” (not “$” nor “\z”)
104-
</td>
105-
<td>Yes
106-
</td>
107-
</tr>
108-
<tr>
109-
<td>Ruby
110-
</td>
111-
<td>“\A” (not “^”)
112-
</td>
113-
<td>“\z” (not “$”)
114-
</td>
115-
<td>Yes
116-
</td>
117-
</tr>
118-
</table>
26+
| Platform | Prepend | Append | $ Permissive? |
27+
|---------------------------------------------------|----------------|-----------------------------------------------------------------------------------------------------|----------------|
28+
| POSIX BRE, POSIX ERE, and ECMAScript (JavaScript) | “^” (not “\A”) | “$” (not “\z” nor “\Z”) | No |
29+
| Perl, .NET/C# | “^” or “\A” | “\z” (not “$”) | Yes |
30+
| Java | “^” or “\A” | “\z”; [“$” works but some documents conflict](./Correctly-Using-Regular-Expressions-Rationale#java) | No |
31+
| PHP | “^” or “\A” | “\z”; “$” with “D” modifier | Yes |
32+
| PCRE | “^” or “\A” | “\z”; “$” with PCRE2_ DOLLAR_ENDONLY | Yes |
33+
| Golang, Rust crate regex, and RE2 | “^” or “\A” | “\z” or “$” | No |
34+
| Python | “^” or “\A” | “\Z” (not “$” nor “\z”) | Yes |
35+
| Ruby | “\A” (not “^”) | “\z” (not “$”) | Yes |
11936

12037
For example, to validate in JavaScript that the input is only “ab” or “de”, use the regex “<tt>^(ab&#x7c;de)$</tt>”. To validate the same thing in Python, use “<tt>^(ab&#x7c;de)\Z</tt>” or “<tt>\A(ab&#x7c;de)\Z</tt>”. Note that the “$” anchor has different meanings among platforms and is often misunderstood; on many platforms it’s permissive by default and doesn’t match only the end of the input. Instead of using “$” on a platform if $ is permissive, consider using an explicit form instead (e.g., “`\n?\z`”). Consider preferring “\A” and “\z” where it’s supported (this is necessary when using Ruby).
12138

0 commit comments

Comments
 (0)