Skip to main content

regexp_replace

Function regexp_replace 

Source
pub fn regexp_replace<'a, V, E, P, R>(
    expr: E,
    pattern: P,
    replacement: R,
) -> SQLExpr<'a, V, <V::DialectMarker as DialectTypes>::Text, E::Nullable, <<E::Aggregate as AggregateKind>::Or<P::Aggregate> as AggregateKind>::Or<R::Aggregate>, (E::Sources, (P::Sources, R::Sources))>
Expand description

Replaces the first POSIX regular expression match (REGEXP_REPLACE), on PostgreSQL.

All arguments must be text. The result is text and keeps expr’s nullability. To replace every match, use regexp_replace_flags with "g".

§Examples

let cleaned = regexp_replace(users.name, "[^a-z]", "");
assert_eq!(cleaned.sql(), r#"REGEXP_REPLACE ("users"."name", $1, $2)"#);