// 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#"AssemblyVersion\("[\d\.\*]+""#).unwrap();
let string = "using System.Reflection;
using System.Runtime.CompilerServices;
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(\"Intergraph.PPM.ApiUtilities\")]
[assembly: AssemblyDescription(\"\")]
[assembly: AssemblyConfiguration(\"\")]
[assembly: AssemblyCompany(\"Microsoft\")]
[assembly: AssemblyProduct(\"Intergraph.PPM.ApiUtilities\")]
[assembly: AssemblyCopyright(\"Copyright © Microsoft 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(\"dd3e45dc-43eb-4ef8-9a6c-614832357ed8\")]
// 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(\"1.0.*\")]
[assembly: AssemblyVersion(\"1.0.0.0\")]
[assembly: AssemblyFileVersion(\"1.0.0.0\")]
[assembly: InternalsVisibleTo(\"Intergraph.PPM.ApiUtilities.UnitTests\")]
";
// 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/