// 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#"(?m)^\[assembly: AssemblyInformationalVersion\(\"(?P<version>[0-9]+(\.([0-9]+|\*)){1,3})\"\)\].*$"#).unwrap();
let string = "using System.Reflection;
using System.Resources;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle(\"MRC+\")]
[assembly: AssemblyDescription(\"MRC+ Configuration\")]
[assembly: AssemblyConfiguration(\"\")]
[assembly: AssemblyCompany(\"Kongsberg Seatex AS\")]
[assembly: AssemblyProduct(\"MRC+\")]
[assembly: AssemblyCopyright(\"Copyright © Kongsberg Seatex AS 2009 - 2015\")]
[assembly: AssemblyTrademark(\"\")]
[assembly: AssemblyCulture(\"\")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid(\"fd48eeca-4024-4955-aae1-e2279d13d262\")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion(\"5.6.*\")]
[assembly: AssemblyVersion(\"5.7.*\")]
[assembly: AssemblyFileVersion(\"5.7.1\")]
[assembly: AssemblyInformationalVersion(\"5.7.1.7\")] //Hurra!
[assembly: NeutralResourcesLanguage(\"en\")]
";
// result will be a tuple containing the start and end indices for the first match in the string
let result = regex.captures(string);
let (start, end) = match result {
Some((s, e)) => (s, e),
None => {
// ...
}
};
println!("{}", &string[start, end]);
}
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/