-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_regex.rs
More file actions
33 lines (27 loc) · 933 Bytes
/
debug_regex.rs
File metadata and controls
33 lines (27 loc) · 933 Bytes
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
use regex::Regex;
fn main() {
let heading_regex = Regex::new(
r#"(?s)<h([1-6])(?:.*?id=["']([^"']+)["'])?.*?>(.*?)</h[1-6]>"#
).unwrap();
let html = r#"
<h1 id="intro">Introduction</h1>
<h2 id="overview">Overview</h2>
"#;
println!("Testing Heading Regex:");
for cap in heading_regex.captures_iter(html) {
println!("Matched: {:?}", cap);
}
let pre_regex = Regex::new(r#"(?s)<pre[^>]*>\s*<code[^>]*class="language-([^"]+)"[^>]*>(.*?)</code>\s*</pre>"#).unwrap();
let code_html = r#"<pre><code class="language-rust">fn main() {
println!("Hello, World!");
}</code></pre>"#;
println!("\nTesting Pre Regex:");
if pre_regex.is_match(code_html) {
println!("Matched!");
for cap in pre_regex.captures_iter(code_html) {
println!("Capture: {:?}", cap);
}
} else {
println!("Not matched!");
}
}