// 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"(?x)<script>
(?:(?!</script>)[\s\S])*
(?:google-analytics)
(?:(?!</script>)[\s\S])*
</script>").unwrap();
let string = " <script src=\"js/min/test.min.js\"></script>
<script>
$('#buttons').share({
networks: ['twitter'],
});
</script>
<!--[if lt IE 9]>
<script src=\"js/plugins/html5shiv.js\"></script>
<script src=\"js/plugins/selectivizr.js\"></script>
<![endif]-->
<!-- location for site scripts -->
<div id=\"scripts\">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-55555-1', 'auto', 'tracker');
ga('tracker.send', 'pageview');
</script></div> <!-- /#lpsite-scripts -->
<div id=\"lppage-scripts\">
</div>
<script type=\"text/javascript\" src=\"js/min/form-validation.min.js\"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-55555-1', 'auto', 'tracker');
ga('lptracker.send', 'pageview');
</script>
";
// 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/