datafusion_functions::regex::regexpreplace

Function regexp_replace

Source
pub fn regexp_replace<'a, T: OffsetSizeTrait, V, B>(
    string_array: V,
    pattern_array: B,
    replacement_array: B,
    flags: Option<&ArrayRef>,
) -> Result<ArrayRef>
where V: ArrayAccessor<Item = &'a str>, B: ArrayAccessor<Item = &'a str>,
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?;