pub fn extract_code(text: &str) -> Option<CodeExtraction> {
    // <begin rant>
    // The regex I want to use is (?<=```)(rs|.*)((.|\n)*)(?=```)
    // but no lookahead or lookbehind support in rust's regex lib
    // which is TRASH (kidding)
    //
    // The regex I'm stuck with is !run(.*)\n```(rs|.*)((.|\n)*)``` which
    // would require more massaging after processing.
    // it will have to do until the regex maintainers realize that
    // these "feature limitations" put rust's regex engine on par
    // with the same one used in the Safari web browser (also trash)
    // </end rant>
    let re = Regex::new(r"!run(.*)\n```(rs|.*)((.|\n)*)```").unwrap();
    let captures_opt = re.captures(text);

    captures_opt.as_ref()?;

    // Have matches, return some
    let captures = captures_opt.unwrap();
    let argument_capture = captures.get(1);
    let code_capture = captures.get(3);
    Some(CodeExtraction {
        code: code_capture.map(|m| String::from(m.as_str())),
        args: argument_capture.map(|m| String::from(m.as_str())),
    })
}
/// Extracts source code from a command message.
/// If no code is extractable, None is returned
/// Otherwise, you will get Some string
Extracts source code from a command message.
If no code is extractable, None is returned
Otherwise, you will get Some string
Extracts source code from a command message . If no code is extractable None is returned Otherwise you will get Some string
pub fn extract_code(text: &str) -> Option<CodeExtraction> {
    // <begin rant>
    // The regex I want to use is (?<=```)(rs|.*)((.|\n)*)(?=```)
    // but no lookahead or lookbehind support in rust's regex lib
    // which is TRASH (kidding)
    //
    // The regex I'm stuck with is !run(.*)\n```(rs|.*)((.|\n)*)``` which
    // would require more massaging after processing.
    // it will have to do until the regex maintainers realize that
    // these "feature limitations" put rust's regex engine on par
    // with the same one used in the Safari web browser (also trash)
    // </end rant>
    let re = Regex::new(r"!run(.*)\n```(rs|.*)((.|\n)*)```").unwrap();
    let captures_opt = re.captures(text);
    captures_opt.as_ref()?;
    // Have matches, return some
    let captures = captures_opt.unwrap();
    let argument_capture = captures.get(1);
    let code_capture = captures.get(3);
    Some(CodeExtraction {
        code: code_capture.map(|m| String::from(m.as_str())),
        args: argument_capture.map(|m| String::from(m.as_str())),
    })
}
pub fn extract_code ( text : & str ) -> Option < CodeExtraction > { // <begin rant> // The regex I want to use is (?<=```)(rs|.*)((.|\n)*)(?=```) // but no lookahead or lookbehind support in rust's regex lib // which is TRASH (kidding) // // The regex I'm stuck with is !run(.*)\n```(rs|.*)((.|\n)*)``` which // would require more massaging after processing. // it will have to do until the regex maintainers realize that // these "feature limitations" put rust's regex engine on par // with the same one used in the Safari web browser (also trash) // </end rant> let re = Regex :: new ( r"!run(.*)\n```(rs|.*)((.|\n)*)```" ) . unwrap ( ) ; let captures_opt = re . captures ( text ) ; captures_opt . as_ref ( ) ? ; // Have matches, return some let captures = captures_opt . unwrap ( ) ; let argument_capture = captures . get ( 1 ) ; let code_capture = captures . get ( 3 ) ; Some ( CodeExtraction { code : code_capture . map ( | m | String :: from ( m . as_str ( ) ) ) , args : argument_capture . map ( | m | String :: from ( m . as_str ( ) ) ) , } ) }
Extracts source code from a command message.
Extracts source code from a command message .
text
&str
text
&str