Function magnus::backref_get

source ·
pub fn backref_get() -> Option<RMatch>
Expand description

Returns the result of the most recent regexp match.

§Panics

Panics if called from a non-Ruby thread. See Ruby::backref_get for the non-panicking version.

§Examples

use magnus::{backref_get, RRegexp};

let regexp = RRegexp::new("b(.)r", Default::default()).unwrap();
let result = regexp.reg_match("foo bar baz").unwrap();
assert_eq!(result, Some(4));

let match_data = backref_get().unwrap();
assert_eq!(
    match_data.matched().to_string().unwrap(),
    String::from("bar")
);
assert_eq!(
    match_data.nth_match(1).map(|v| v.to_string().unwrap()),
    Some(String::from("a"))
);