pub fn exec(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
    let arg_str = get_argument::<String>(args, 0)?;
    let mut last_index = from_value::<usize>(this.get_field("lastIndex")).map_err(to_value)?;
    let result = this.with_internal_state_ref(|regex: &RegExp| {
        let mut locations = regex.matcher.capture_locations();
        let result =
            match regex
                .matcher
                .captures_read_at(&mut locations, arg_str.as_str(), last_index)
            {
                Some(m) => {
                    if regex.use_last_index {
                        last_index = m.end();
                    }
                    let mut result = Vec::with_capacity(locations.len());
                    for i in 0..locations.len() {
                        if let Some((start, end)) = locations.get(i) {
                            result.push(to_value(
                                arg_str.get(start..end).expect("Could not get slice"),
                            ));
                        } else {
                            result.push(Gc::new(ValueData::Undefined));
                        }
                    }
                    let result = to_value(result);
                    result.set_prop_slice("index", Property::default().value(to_value(m.start())));
                    result.set_prop_slice("input", Property::default().value(to_value(arg_str)));
                    result
                }
                None => {
                    if regex.use_last_index {
                        last_index = 0;
                    }
                    Gc::new(ValueData::Null)
                }
            };
        Ok(result)
    });
    this.set_field_slice("lastIndex", to_value(last_index));
    result
}
/// Search for a match between this regex and a specified string
Search for a match between this regex and a specified string
Search for a match between this regex and a specified string
pub fn exec(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
    let arg_str = get_argument::<String>(args, 0)?;
    let mut last_index = from_value::<usize>(this.get_field("lastIndex")).map_err(to_value)?;
    let result = this.with_internal_state_ref(|regex: &RegExp| {
        let mut locations = regex.matcher.capture_locations();
        let result =
            match regex
                .matcher
                .captures_read_at(&mut locations, arg_str.as_str(), last_index)
            {
                Some(m) => {
                    if regex.use_last_index {
                        last_index = m.end();
                    }
                    let mut result = Vec::with_capacity(locations.len());
                    for i in 0..locations.len() {
                        if let Some((start, end)) = locations.get(i) {
                            result.push(to_value(
                                arg_str.get(start..end).expect("Could not get slice"),
                            ));
                        } else {
                            result.push(Gc::new(ValueData::Undefined));
                        }
                    }
                    let result = to_value(result);
                    result.set_prop_slice("index", Property::default().value(to_value(m.start())));
                    result.set_prop_slice("input", Property::default().value(to_value(arg_str)));
                    result
                }
                None => {
                    if regex.use_last_index {
                        last_index = 0;
                    }
                    Gc::new(ValueData::Null)
                }
            };
        Ok(result)
    });
    this.set_field_slice("lastIndex", to_value(last_index));
    result
}
pub fn exec ( this : & Value , args : & [ Value ] , _ : & mut Interpreter ) -> ResultValue { let arg_str = get_argument :: < String > ( args , 0 ) ? ; let mut last_index = from_value :: < usize > ( this . get_field ( " " ) ) . map_err ( to_value ) ? ; let result = this . with_internal_state_ref ( | regex : & RegExp | { let mut locations = regex . matcher . capture_locations ( ) ; let result = match regex . matcher . captures_read_at ( & mut locations , arg_str . as_str ( ) , last_index ) { Some ( m ) => { if regex . use_last_index { last_index = m . end ( ) ; } let mut result = Vec :: with_capacity ( locations . len ( ) ) ; for i in 0 .. locations . len ( ) { if let Some ( ( start , end ) ) = locations . get ( i ) { result . push ( to_value ( arg_str . get ( start .. end ) . expect ( " " ) , ) ) ; } else { result . push ( Gc :: new ( ValueData :: Undefined ) ) ; } } let result = to_value ( result ) ; result . set_prop_slice ( " " , Property :: default ( ) . value ( to_value ( m . start ( ) ) ) ) ; result . set_prop_slice ( " " , Property :: default ( ) . value ( to_value ( arg_str ) ) ) ; result } None => { if regex . use_last_index { last_index = 0 ; } Gc :: new ( ValueData :: Null ) } } ; Ok ( result ) } ) ; this . set_field_slice ( " " , to_value ( last_index ) ) ; result }
Search for a match between this regex and a specified string
Search for a match between this regex and a specified string
this
&Value
args
&mut Interpreter
this
&Value
args
&mut Interpreter