Skip to content

Expr.Str (StringOps) ​

Namespace: Polars.FSharp

Instance Methods ​

Contains ​

Check if the string contains a substring or regex pattern.

fsharp
member Contains(pattern: string, ?literal: bool, ?strict: bool) : Expr

Parameters

NameTypeDescription
patternstring-
literalbool (optional)-
strictbool (optional)-

ContainsAny ​

Use the Aho-Corasick algorithm to find matches. Determines if any of the patterns are contained in the string.

fsharp
member ContainsAny(pattern: string, ?asciiCaseInsensitive: bool) : Expr

Parameters

NameTypeDescription
patternstring-
asciiCaseInsensitivebool (optional)Enable ASCII-aware case-insensitive matching. When this option is enabled, searching will be performed without respect to case for ASCII letters (a-z and A-Z) only.

CountMatches ​

Count all successive non-overlapping regex matches.

fsharp
member CountMatches(pattern: string, ?literal: bool) : Expr

Parameters

NameTypeDescription
patternstringA valid regular expression pattern, compatible with the regex crate.
literalbool (optional)Treat pattern as a literal string, not as a regular expression.

Returns: Expression of data type UInt32. Returns null if the original value is null.


Decode ​

Decode values using the provided encoding.

fsharp
member Decode(encoding: TransferEncoding, ?strict: bool) : Expr

Parameters

NameTypeDescription
encodingTransferEncodingThe encoding to use.
strictbool (optional)Raise an error if the underlying value cannot be decoded, otherwise mask out with a null value.

Returns: Expression of data type Binary.


Encode ​

Encode values using the provided encoding.

fsharp
member Encode(encoding: TransferEncoding) : Expr

Parameters

NameTypeDescription
encodingTransferEncodingThe encoding to use.

Returns: Expression of data type String.


EndsWith ​

Check if string ends with a specific suffix.

fsharp
member EndsWith(suffix: string) : Expr

Parameters

NameTypeDescription
suffixstring-

EscapeRegex ​

Returns string values with all regular expression meta characters escaped.

fsharp
member EscapeRegex : unit -> Expr

Extract ​

Extract the first match of a regex pattern.

fsharp
member Extract(pattern: string, ?groupIndex: int) : Expr

Parameters

NameTypeDescription
patternstringRegex pattern with capture groups.
groupIndexint (optional)The index of the capture group to extract (usually 1).

ExtractAll ​

Extract all matches for the given regex pattern. Extract each successive non-overlapping regex match in an individual string as a list. If the haystack string is null, null is returned.

fsharp
member ExtractAll(pattern: string) : Expr

Parameters

NameTypeDescription
patternstringA valid regular expression pattern, compatible with the regex crate.

Returns: Expression of data type List(String).


ExtractGroups ​

Extract all capture groups for the given regex pattern.

fsharp
member ExtractGroups(pattern: string) : Expr

Parameters

NameTypeDescription
patternstringA valid regular expression pattern containing at least one capture group, compatible with the regex crate.

Returns: Expression of data type Struct with fields of data type String.


ExtractMany ​

Use the Aho-Corasick algorithm to extract many matches.This method supports matching on string literals only, and does not support regular expression matching.

fsharp
member ExtractMany(
    patterns: Expr,
    ?asciiCaseInsensitive: bool,
    ?overlapping: bool,
    ?leftmost: bool
) : Expr

Parameters

NameTypeDescription
patternsExprString patterns to search.
asciiCaseInsensitivebool (optional)Enable ASCII-aware case-insensitive matching. When this option is enabled, searching will be performed without respect to case for ASCII letters (a-z and A-Z) only.
overlappingbool (optional)Whether matches may overlap.
leftmostbool (optional)Guarantees in case there are overlapping matches that the leftmost match is used. In case there are multiple candidates for the leftmost match the pattern which comes first in patterns is used. May not be used together with overlapping = True.

Find ​

Return the bytes offset of the first substring matching a pattern. If the pattern is not found, returns None.

fsharp
member Find(pattern: string, ?literal: bool, ?strict: bool) : Expr

Parameters

NameTypeDescription
patternstringA valid regular expression pattern, compatible with the regex crate.
literalbool (optional)Treat pattern as a literal string, not as a regular expression.
strictbool (optional)Raise an error if the underlying pattern is not a valid regex, otherwise mask out with a null value.

FindMany ​

Find the indices of all matches of a pattern in a string.

fsharp
member FindMany(
    patterns: Expr,
    ?asciiCaseInsensitive: bool,
    ?overlapping: bool,
    ?leftmost: bool
) : Expr

Parameters

NameTypeDescription
patternsExprThe pattern to search for.
asciiCaseInsensitivebool (optional)Whether to perform an ASCII-only case-insensitive search.
overlappingbool (optional)Whether to allow overlapping matches.
leftmostbool (optional)Whether to search from the left.

Returns: Expression of data type List<int>.


Return the first n characters of each string in a String Series.

fsharp
member Head(n: int) : Expr

Parameters

NameTypeDescription
nintLength of the slice
When the n input is negative, head returns characters up to the n`th from the end of the string. For example, if n = -3, then all characters except the last three are returned.

Returns: Expression of data type String.


Join ​

Vertically concatenate the string values in the column to a single string value.

fsharp
member Join(?delimiter: string, ?ignoreNulls: bool) : Expr

Parameters

NameTypeDescription
delimiterstring (optional)The delimiter to insert between consecutive string values.
ignoreNullsbool (optional)Ignore null values (default). If set to False, null values will be propagated. This means that if the column contains any null values, the output is null.

Returns: Expression of data type String.


JsonDecode ​

Parse string values as JSON. Throws an error if invalid JSON strings are encountered.

fsharp
member JsonDecode(dtype: DataTypeExpr) : Expr
member JsonDecode(dtype: DataType) : Expr

Parameters

NameTypeDescription
dtypeDataTypeExprThe datatype to cast the extracted value to.

JsonPathMatch ​

Extract the first match from a JSON string using the provided JSONPath. Throws errors if invalid JSON strings are encountered. All return values are cast to String, regardless of the original value.

fsharp
member JsonPathMatch(jsonPath: string) : Expr

Parameters

NameTypeDescription
jsonPathstringA valid JSONPath query string.

Returns: Expression of data type String. Contains null values if original value is null or the json_path returns nothing.


LenBytes ​

Get length in bytes.

fsharp
member LenBytes : unit -> Expr

LenChars ​

Return the length of each string as the number of characters.

fsharp
member LenChars : unit -> Expr

Returns: Expression of data type UInt32.


Normalize ​

Returns the Unicode normal form of the string values.

fsharp
member Normalize(form: NormalizationForm) : Expr

Parameters

NameTypeDescription
formNormalizationFormUnicode form to use.

PadEnd ​

Pad the end of the string until it reaches the given length.

fsharp
member PadEnd(length: int, ?fillChar: string) : Expr

Parameters

NameTypeDescription
lengthintPad the string until it reaches this length. Strings with length equal to or greater than this value are returned as-is.
fillCharstring (optional)The character to pad the string with.

PadStart ​

Pad the start of the string until it reaches the given length.

fsharp
member PadStart(length: int, ?fillChar: string) : Expr

Parameters

NameTypeDescription
lengthintPad the string until it reaches this length. Strings with length equal to or greater than this value are returned as-is.
fillCharstring (optional)The character to pad the string with.

Replace ​

Replace first matching regex/literal substring with a new string value.

fsharp
member Replace(
    pattern: string,
    value: string,
    ?literal: bool,
    ?n: int
) : Expr

Parameters

NameTypeDescription
patternstringA valid regular expression pattern, compatible with the regex crate.
valuestringString that will replace the matched substring.
literalbool (optional)Treat pattern as a literal string, not a regex.
nint (optional)Number of matches to replace.

ReplaceAll ​

Replace all occurrences of a pattern with a value.

fsharp
member ReplaceAll(pattern: string, value: string, ?literal: bool) : Expr

Parameters

NameTypeDescription
patternstringThe pattern to search for.
valuestringThe value to replace with.
literalbool (optional)Whether to interpret the pattern as literal value(not Regex).

ReplaceMany ​

Use the Aho-Corasick algorithm to replace many matches.

fsharp
member ReplaceMany(
    patterns: Expr,
    replaceWith: Expr,
    ?asciiCaseInsensitive: bool,
    ?leftmost: bool
) : Expr

Parameters

NameTypeDescription
patternsExprExpression yielding string patterns to search and replace.
replaceWithExprStrings to replace where a pattern was a match. Length must match the length of patterns or have length 1. This can be broadcasted, so it supports many:one and many:many.
asciiCaseInsensitivebool (optional)Enable ASCII-aware case-insensitive matching.
leftmostbool (optional)Guarantees in case there are overlapping matches that the leftmost match is used.

Reverse ​

Returns string values in reversed order.

fsharp
member Reverse : unit -> Expr

Slice ​

Slice the string by offset and length.

fsharp
member Slice(offset: int64, ?length: uint64) : Expr

Parameters

NameTypeDescription
offsetint64Start index.
lengthuint64 (optional)Length of the slice.

Split ​

Split the string by a substring.

fsharp
member Split(
    separator: string,
    ?inclusive: bool,
    ?literal: bool,
    ?strict: bool
) : Expr

Parameters

NameTypeDescription
separatorstring-
inclusivebool (optional)If True, include the split character/string in the results.
literalbool (optional)Treat by as a literal string, not as a regular expression.
strictbool (optional)Raise an error if the underlying pattern is not a valid regex, otherwise mask out with a null value.

Returns: Expression/Series of data type String.


SplitExact ​

Split the string by a substring using n splits. Results in a struct of n+1 fields. If it cannot make n splits, the remaining field elements will be null.

fsharp
member SplitExact(by: string, n: int, ?inclusive: bool) : Expr

Parameters

NameTypeDescription
bystringSubstring to split by.
nintNumber of splits to make.
inclusivebool (optional)If True, include the split character/string in the results.

Returns: Expression/Series of data type Struct with fields of data type String.


SplitN ​

Split the string by a substring, restricted to returning at most n items.

If the number of possible splits is less than n-1, the remaining field elements will be null. If the number of possible splits is n-1 or greater, the last (nth) substring will contain the remainder of the string.

fsharp
member SplitN(by: string, n: int) : Expr

Parameters

NameTypeDescription
bystringSubstring to split by.
nintMax number of items to return.

Returns: Expression/Series of data type Struct with fields of data type String.


StartsWith ​

Check if string starts with a specific prefix.

fsharp
member StartsWith(prefix: string) : Expr

Parameters

NameTypeDescription
prefixstring-

StripChars ​

Remove leading and trailing characters. If matches is null, whitespace is removed.

fsharp
member StripChars(?characters: string) : Expr

Parameters

NameTypeDescription
charactersstring (optional)-

StripCharsEnd ​

Remove trailing characters (Right Trim). If 'matches' is omitted, whitespace is removed.

fsharp
member StripCharsEnd(?characters: string) : Expr

Parameters

NameTypeDescription
charactersstring (optional)-

StripCharsStart ​

Remove leading characters (Left Trim). If 'matches' is omitted, whitespace is removed.

fsharp
member StripCharsStart(?characters: string) : Expr

Parameters

NameTypeDescription
charactersstring (optional)-

StripPrefix ​

Remove a specific prefix string.

fsharp
member StripPrefix(prefix: string) : Expr

Parameters

NameTypeDescription
prefixstring-

StripSuffix ​

Remove a specific suffix string.

fsharp
member StripSuffix(suffix: string) : Expr

Parameters

NameTypeDescription
suffixstring-

Strptime ​

Convert a String column into a Date/Datetime/Time column.

fsharp
member Strptime(
    dtype: DataType,
    ?format: string,
    ?strict: bool,
    ?exact: bool,
    ?cache: bool,
    ?ambiguous: Expr
) : Expr

Parameters

NameTypeDescription
dtypeDataTypeThe data type to convert into. Can be either Date, Datetime, or Time.
formatstring (optional)The parsing format (e.g., "%Y-%m-%d","yyyy-MM-dd"). Null for auto-inference.
strictbool (optional)Raise an error if any conversion fails.
exactbool (optional)Require an exact format match. If False, allow the format to match anywhere in the target string. Conversion to the Time type is always exact.
cachebool (optional)Use a cache of unique, converted dates to apply the datetime conversion.
ambiguousExpr (optional)Determine how to deal with ambiguous datetimes: 'raise' (default): raise 'earliest': use the earliest datetime 'latest': use the latest datetime 'null': set to null

Tail ​

Return the last n characters of each string in a String Series.

fsharp
member Tail(n: int) : Expr

Parameters

NameTypeDescription
nintLength of the slice (integer or expression)
When the n input is negative, head returns characters up to the n`th from the start of the string. For example, if n = -3, then all characters except the first three are returned.

Returns: Expression of data type String.


ToDate ​

Parse string to Date using a format string (e.g., "%Y-%m-%d", 'yyyy-MM-dd').

fsharp
member ToDate(
    ?format: string,
    ?strict: bool,
    ?exact: bool,
    ?cache: bool
) : Expr

Parameters

NameTypeDescription
formatstring (optional)The parsing format (e.g., "%Y-%m-%d", 'yyyy-MM-dd'). Null for auto-inference.
strictbool (optional)If true, raises an error on parsing failure. If false, returns nulls.
exactbool (optional)If true, requires an exact match. If false, allows matching substrings.
cachebool (optional)Use a cache of unique converted dates to speed up parsing.

ToDatetime ​

Convert string to Datetime. If format is null, Polars will attempt to infer it.

fsharp
member ToDatetime(
    ?format: string,
    ?timeUnit: TimeUnit,
    ?timeZone: string,
    ?strict: bool,
    ?exact: bool,
    ?cache: bool,
    ?ambiguous: Expr
) : Expr

Parameters

NameTypeDescription
formatstring (optional)The parsing format (e.g., "%Y-%m-%d","yyyy-MM-dd"). Null for auto-inference.
timeUnitTimeUnit (optional)Target time unit. Null to use default (usually Microseconds).
timeZonestring (optional)Target time zone (e.g., "UTC", "Asia/Shanghai").
strictbool (optional)If true, raises an error on parsing failure. If false, returns nulls.
exactbool (optional)If true, requires an exact match. If false, allows matching substrings.
cachebool (optional)Use a cache of unique converted dates to speed up parsing.
ambiguousExpr (optional)Determine how to deal with ambiguous datetimes: 'raise' (default): raise 'earliest': use the earliest datetime 'latest': use the latest datetime 'null': set to null

ToDecimal ​

Convert a String column into a Decimal column.

fsharp
member ToDecimal(scale: int) : Expr

Parameters

NameTypeDescription
scaleintNumber of digits after the comma to use for the decimals.

ToInteger ​

Convert a String column into an Integer column with the specified radix (base).

fsharp
member ToInteger(?radix: int, ?dtype: DataType, ?strict: bool) : Expr

Parameters

NameTypeDescription
radixint (optional)Positive integer or expression which is the base of the string we are parsing. Default is 10.
dtypeDataType (optional)Integer data type to cast the result to. Default is Int64.
strictbool (optional)If true, raises ComputeError on failure. If false, silently converts to Null.

Returns: Expression of destinated integer data type.


ToLowercase ​

Convert to lowercase.

fsharp
member ToLowercase : unit -> Expr

ToTime ​

Convert a String column into a Time column.

fsharp
member ToTime(
    ?format: string,
    ?strict: bool,
    ?exact: bool,
    ?cache: bool
) : Expr

Parameters

NameTypeDescription
formatstring (optional)The parsing format (e.g., "%H:%M:%S","HH-mm-ss"). Null for auto-inference.
strictbool (optional)Raise an error if any conversion fails.
exactbool (optional)If true, requires an exact match. If false, allows matching substrings.
cachebool (optional)Use a cache of unique, converted times to apply the conversion.

ToTitlecase ​

Modify strings to their titlecase equivalent.

This is a form of case transform where the first letter of each word is capitalized, with the rest of the word in lowercase. Non-alphanumeric characters define the word boundaries.

fsharp
member ToTitlecase : unit -> Expr

ToUppercase ​

Convert to uppercase.

fsharp
member ToUppercase : unit -> Expr

Zfill ​

Pad the start of the string with zeros until it reaches the given length.

A sign prefix (-) is handled by inserting the padding after the sign character rather than before.

This method is intended for padding numeric strings. If your data contains non-ASCII characters, use pad_start() instead.

fsharp
member Zfill(length: int) : Expr

Parameters

NameTypeDescription
lengthintPad the string until it reaches this length. Strings with length equal to or greater than this value are returned as-is.

Released under the MIT License. Powered by the Polars Rust core & Apache Arrow.