spinoso_regexp

Function nth_match_group_bytes

Source
pub fn nth_match_group_bytes(group: NonZeroUsize) -> Cow<'static, [u8]>
Expand description

Global variable name for the nth capture group from a Regexp match.

Ruby tags captures from the last Regexp match with global variables of the form $1, $2, $3, etc. This function accepts NonZeroUsize because $0 is not a valid Regexp capture group name in Ruby ($0 refers to the program name).

This function may return either a &'static [u8] or an owned Vec<u8> for a given capture group name. This function differs from nth_match_group by returning Cow<'static, [u8]>.

ยงExamples

use core::num::NonZeroUsize;

use spinoso_regexp::nth_match_group_bytes;

let group = NonZeroUsize::new(1)?;
let global_name = nth_match_group_bytes(group);
assert_eq!(&*global_name, b"$1");

let group = NonZeroUsize::new(27)?;
let global_name = nth_match_group_bytes(group);
assert_eq!(&*global_name, b"$27");