| 124 | /* groups: capture groups of the first match, or None. */ |
| 125 | #[plugin_fn] |
| 126 | fn groups(pattern: String, string: String) -> Result<Option<Handle>> { |
| 127 | let Some(f) = rx(main::find(&pattern, &string, Mode::Search))? else { return Ok(None); }; |
| 128 | let list = Handle::new_list()?; |
| 129 | for g in &f.groups { |
| 130 | let h = match g { |
| 131 | Some(s) => encode(Value::Bytes(s.clone().into_bytes()))?, |
| 132 | None => encode(Value::None)?, |
| 133 | }; |
| 134 | list.call("append", &[h.raw()])?; |
| 135 | } |
| 136 | Ok(Some(list)) |
| 137 | } |
| 138 | |
| 139 | /* span: codepoint start and end of the first match as a two element list. */ |
| 140 | #[plugin_fn] |