Function datafusion::functions::regex::regexpreplace::regexp_replace

source ·
pub fn regexp_replace<T>(
    args: &[Arc<dyn Array>],
) -> Result<Arc<dyn Array>, DataFusionError>
where T: OffsetSizeTrait,
Expand description

Replaces substring(s) matching a PCRE-like regular expression.

The full list of supported features and syntax can be found at https://docs.rs/regex/latest/regex/#syntax

Supported flags with the addition of ‘g’ can be found at https://docs.rs/regex/latest/regex/#grouping-and-flags

§Examples

let ctx = SessionContext::new();
let df = ctx.read_csv("tests/data/regex.csv", CsvReadOptions::new()).await?;

// use the regexp_replace function to replace substring(s) without flags
let df = df.with_column(
    "a",
    regexp_replace(vec![col("values"), col("patterns"), col("replacement")])
)?;
// use the regexp_replace function to replace substring(s) with flags
let df = df.with_column(
    "b",
    regexp_replace(vec![col("values"), col("patterns"), col("replacement"), col("flags")]),
)?;

// literals can be used as well
let df = df.with_column(
    "c",
    regexp_replace(vec![lit("foobarbequebaz"), lit("(bar)(beque)"), lit(r"\2")]),
)?;

df.show().await?;