// include the latest version of the regex crate in your Cargo.toml
extern crate regex;
use regex::Regex;
fn main() {
let regex = Regex::new(r#"(?siU)(<(a|link|script|div|iframe)(?:\s[^>]*[\s"']|\s)(?:(data-settings|href|data-src)(?!\s*=\s*[\\]?"\b))=([\"\']??))([^\4]*)(\4[^>]*>)"#).unwrap();
let string = "<iframe hcb-fetch-image-from=\"<iframe src="https://player.vimeo.com/video/33234? dnt=1" h=4725157e" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>\" class=\"elementor-video-iframe\" allowfullscreen title=\"vimeo Video Player\" data-lazy-load=\"https://player.vimeo.com/video/651646452?color&autopause=0&loop=0&muted=0&title=1&portrait=1&byline=1#t=\"></iframe>
This is an regex built on top of <a href='https://www.the-art-of-web.com/php/parse-links/' class=\"test\">
This is an regex built on top of <a
href='https://www.the-art-of-web.com/php/parse-links/' class=\"test\">
This is an regex built on top of <a test=\"\"href='https://www.the-art-of-web.com/php/parse-links/' class=\"test\">
This is an regex built on top of <a test=\"\" not-matching-href='https://www.the-art-of-web.com/php/parse-links/' class=\"test\">
This is link <link rel=\"stylesheet\" href=\"http://google.com\">
This is script <script src=\"http://devowl.io\">
This is script <script data-src=\"http://devowl.io\">
This is script <script wup src=\"http://devowl.io\">
Another line
<link data-src=\"{"youtube_url":"https:\\/\\/www.youtube.com\\/watch"}\" another=\"attribute\" />
<div class=\"elementor-element elementor-element-bc17ee6 elementor-aspect-ratio-169 elementor-widget elementor-widget-video\" data-id=\"bc17ee6\" data-element_type=\"widget\" data-settings=\"{"youtube_url":"https:\\/\\/www.youtube.com\\/watch?v=XHOmBV4js_E","video_type":"youtube","controls":"yes","aspect_ratio":"169"}\" data-widget_type=\"video.default\">
<link hcb-fetch-image-from=\"<a href="https://player.vimeo.com/video/33234?screen;picture-in-picture"></a>\" href=\"https://example.com/link.css\" />
<div data-markers=\"[{"title":"Stylish remodeled room","latitude":40,"longitude":-73,"content":"<div class=\\"hp-listing hp-listing--map-block\\"><h5 class=\\"hp-listing__title\\"><a href=\\"https:\\/\\/example.de\\/listing\\/stylish-remodeled-room\\/\\">Stylish remodeled room<\\/a>\\n<\\/h5><\\/div>"}]\" class=\"hp-listing__map hp-listing__map widget hp-map\" data-max-zoom=\"18\" data-component=\"map\" href=\"test\"></div>
<div class=\"wpforms-container wpforms-container-full\" id=\"wpforms-1081\"><form id=\"wpforms-form-1081\" class=\"wpforms-validate wpforms-form\" data-formid=\"1081\" method=\"post\" enctype=\"multipart/form-data\" action=\"/wpforms/\" data-token=\"43285f0e3d425addb1b108bd61d3dee9\"><noscript class=\"wpforms-error-noscript\">Please enable JavaScript in your browser to complete this form.</noscript><div class=\"wpforms-field-container\"><div id=\"wpforms-1081-field_0-container\" class=\"wpforms-field wpforms-field-name\" data-field-id=\"0\"><label class=\"wpforms-field-label\" for=\"wpforms-1081-field_0\">Name <span class=\"wpforms-required-label\">*</span></label><div class=\"wpforms-field-row wpforms-field-medium\"><div class=\"wpforms-field-row-block wpforms-first wpforms-one-half\"><input type=\"text\" id=\"wpforms-1081-field_0\" class=\"wpforms-field-name-first wpforms-field-required\" name=\"wpforms[fields][0][first]\" required><label for=\"wpforms-1081-field_0\" class=\"wpforms-field-sublabel after \">First</label></div><div class=\"wpforms-field-row-block wpforms-one-half\"><input type=\"text\" id=\"wpforms-1081-field_0-last\" class=\"wpforms-field-name-last wpforms-field-required\" name=\"wpforms[fields][0][last]\" required><label for=\"wpforms-1081-field_0-last\" class=\"wpforms-field-sublabel after \">Last</label></div></div></div><div id=\"wpforms-1081-field_1-container\" class=\"wpforms-field wpforms-field-email\" data-field-id=\"1\"><label class=\"wpforms-field-label\" for=\"wpforms-1081-field_1\">Email <span class=\"wpforms-required-label\">*</span></label><input type=\"email\" id=\"wpforms-1081-field_1\" class=\"wpforms-field-medium wpforms-field-required\" name=\"wpforms[fields][1]\" required></div><div id=\"wpforms-1081-field_2-container\" class=\"wpforms-field wpforms-field-textarea\" data-field-id=\"2\"><label class=\"wpforms-field-label\" for=\"wpforms-1081-field_2\">Comment or Message <span class=\"wpforms-required-label\">*</span></label><textarea id=\"wpforms-1081-field_2\" class=\"wpforms-field-medium wpforms-field-required\" name=\"wpforms[fields][2]\" required></textarea></div></div><div class=\"wpforms-submit-container\" ><input type=\"hidden\" name=\"wpforms[id]\" value=\"1081\"><input type=\"hidden\" name=\"wpforms[author]\" value=\"1\"><input type=\"hidden\" name=\"wpforms[post_id]\" value=\"1082\"><button type=\"submit\" name=\"wpforms[submit]\" class=\"wpforms-submit \" id=\"wpforms-submit-1081\" value=\"wpforms-submit\" aria-live=\"assertive\" data-alt-text=\"Sending...\" data-submit-text=\"Submit\">Submit</button></div></form></div> <!-- .wpforms-container --> </div><!-- .entry-content -->
<footer class=\"entry-meta\">
<span class=\"edit-link\"><a class=\"post-edit-link\" href=\"http://gitlab-ci-runner-3.owlsrv.de:10000/wp-admin/post.php?post=1082&action=edit\">Edit</a></span> </footer><!-- .entry-meta -->
</article><!-- #post-1082 -->";
// result will be an iterator over tuples containing the start and end indices for each match in the string
let result = regex.captures_iter(string);
for mat in result {
println!("{:?}", mat);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Rust, please visit: https://docs.rs/regex/latest/regex/