Regex

Regex example for WASM

Code

New (work in progress)

use regex::Regex;
use space_lib::{space, Result};
use serde::{Deserialize, Serialize};

#[derive(Deserialize)]
struct Input {
    text: String,
    regex: String,
}

#[derive(Serialize)]
struct Output {
    captures: Vec<String>,
}

#[space]
fn main(input: Input) -> Result<Output> {
    let re = Regex::new(&input.regex)?;
    let captures = re.captures(&input.text).map(|captures| {
        captures
            .iter()
            .skip(1)
            .flat_map(|r#match| r#match.map(|it| it.as_str().to_owned()))
            .collect::<Vec<_>>()
    });
    match captures {
        Some(captures) => Ok(Output { captures }),
        None => Err("No captures were found")?,
    }
}

Old

Node Definition

Last updated

Was this helpful?