diff --git a/content/v2.0/reference/flux/functions/regexp/_index.md b/content/v2.0/reference/flux/functions/regexp/_index.md new file mode 100644 index 000000000..e230a5c34 --- /dev/null +++ b/content/v2.0/reference/flux/functions/regexp/_index.md @@ -0,0 +1,22 @@ +--- +title: Flux regular expressions package +list_title: Regular expressions package +description: > + The Flux regular expressions package includes functions that provide enhanced + regular expression functionality. Import the `regexp` package. +menu: + v2_0_ref: + name: Regular expressions + parent: Flux packages and functions +weight: 205 +v2.0/tags: [regex, functions] +--- + +The Flux regular expressions package includes functions that provide enhanced +regular expression functionality. Import the `regexp` package. + +```js +import "regexp" +``` + +{{< children type="functions" show="pages" >}} diff --git a/content/v2.0/reference/flux/functions/regexp/compile.md b/content/v2.0/reference/flux/functions/regexp/compile.md new file mode 100644 index 000000000..8a5f45cca --- /dev/null +++ b/content/v2.0/reference/flux/functions/regexp/compile.md @@ -0,0 +1,50 @@ +--- +title: regexp.compile() function +description: > + The `regexp.compile()` function parses a regular expression and, if successful, + returns a Regexp object that can be used to match against text. +menu: + v2_0_ref: + name: regexp.compile + parent: Regular expressions +weight: 301 +--- + +The `regexp.compile()` function parses a regular expression and, if successful, +returns a Regexp object that can be used to match against text. + +_**Output data type:** Regexp_ + +```js +import "regexp" + +regexp.compile(v: "abcd") + +// Returns the regexp object `abcd` +``` + +## Parameters + +### v +The string value to parse into a regular expression. + +_**Data type:** String_ + +## Examples + +###### Use a string value as a regular expression +```js +import "regexp" + +data + |> map(fn: (r) => ({ + r with + regexStr: r.regexStr, + _value: r._value, + firstRegexMatch: findString( + r: regexp.compile(v: regexStr), + v: r._value + ) + }) + ) +``` diff --git a/content/v2.0/reference/flux/functions/regexp/findstring.md b/content/v2.0/reference/flux/functions/regexp/findstring.md new file mode 100644 index 000000000..ac0f98e86 --- /dev/null +++ b/content/v2.0/reference/flux/functions/regexp/findstring.md @@ -0,0 +1,51 @@ +--- +title: regexp.findString() function +description: The `regexp.findString()` function returns the left-most regular expression match in a string. +menu: + v2_0_ref: + name: regexp.findString + parent: Regular expressions +weight: 301 +related: + - /v2.0/reference/flux/functions/regexp/splitregexp +--- + +The `regexp.findString()` function returns the left-most regular expression match in a string. + +_**Output data type:** String_ + +```js +import "regexp" + +findString(r: /foo.?/, v: "seafood fool") + +// Returns "food" +``` + +## Parameters + +### r +The regular expression used to search `v`. + +_**Data type:** Regexp_ + +### v +The string value to search. + +_**Data type:** String_ + +## Examples + +###### Find the first regular expression match in each row +```js +import "regexp" + +data + |> map(fn: (r) => ({ + r with + message: r.message, + regexp: r.regexp, + match: regexp.findString(r: r.regexp, v: r.message) + }) + ) +``` diff --git a/content/v2.0/reference/flux/functions/regexp/findstringindex.md b/content/v2.0/reference/flux/functions/regexp/findstringindex.md new file mode 100644 index 000000000..49a1d7a47 --- /dev/null +++ b/content/v2.0/reference/flux/functions/regexp/findstringindex.md @@ -0,0 +1,57 @@ +--- +title: regexp.findStringIndex() function +description: > + The `regexp.findStringIndex()` function returns a two-element array of integers defining + the beginning and ending indexes of the left-most regular expression match in a string. +menu: + v2_0_ref: + name: regexp.findStringIndex + parent: Regular expressions +weight: 301 +related: + - /v2.0/reference/flux/functions/regexp/compile +--- + +The `regexp.findStringIndex()` function returns a two-element array of integers defining +the beginning and ending indexes of the left-most regular expression match in a string. + +_**Output data type:** Array of Integers_ + +```js +import "regexp" + +regexp.findStringIndex(r: /ab?/, v: "tablet") + +// Returns [1, 3] +``` + +## Parameters + +### r +The regular expression used to search `v`. + +_**Data type:** Regexp_ + +### v +The string value to search. + +_**Data type:** String_ + +## Examples + +###### Index the bounds of first regular expression match in each row +```js +import "regexp" + +data + |> map(fn: (r) => ({ + r with + regexStr: r.regexStr, + _value: r._value, + matchIndex: regexp.findStringIndex( + r: regexp.compile(r.regexStr), + v: r._value + ) + }) + ) +``` diff --git a/content/v2.0/reference/flux/functions/regexp/getstring.md b/content/v2.0/reference/flux/functions/regexp/getstring.md new file mode 100644 index 000000000..f4528a091 --- /dev/null +++ b/content/v2.0/reference/flux/functions/regexp/getstring.md @@ -0,0 +1,45 @@ +--- +title: regexp.getString() function +description: The `regexp.getString()` function returns the source string used to compile a regular expression. +menu: + v2_0_ref: + name: regexp.getString + parent: Regular expressions +weight: 301 +related: + - /v2.0/reference/flux/functions/regexp/compile +--- + +The `regexp.getString()` function returns the source string used to compile a regular expression. + +_**Output data type:** String_ + +```js +import "regexp" + +regexp.getString(r: /[a-zA-Z]/) + +// Returns "[a-zA-Z]" +``` + +## Parameters + +### r +The regular expression object to convert to a string. + +_**Data type:** Regexp_ + +## Examples + +###### Convert regular expressions into strings in each row +```js +import "regexp" + +data + |> map(fn: (r) => ({ + r with + regex: r.regex, + regexStr: regexp.getString(r: r.regex) + }) + ) +``` diff --git a/content/v2.0/reference/flux/functions/regexp/matchregexpstring.md b/content/v2.0/reference/flux/functions/regexp/matchregexpstring.md new file mode 100644 index 000000000..4a5c39cf7 --- /dev/null +++ b/content/v2.0/reference/flux/functions/regexp/matchregexpstring.md @@ -0,0 +1,51 @@ +--- +title: regexp.matchRegexpString() function +description: > + The `regexp.matchRegexpString()` function tests if a string contains any match + to a regular expression. +menu: + v2_0_ref: + name: regexp.matchRegexpString + parent: Regular expressions +weight: 301 +--- + +The `regexp.matchRegexpString()` function tests if a string contains any match +to a regular expression. + +_**Output data type:** Boolean_ + +```js +import "regexp" + +regexp.matchRegexpString(r: /(gopher){2}/, v: "gophergophergopher") + +// Returns true +``` + +## Parameters + +### r +The regular expression used to search `v`. + +_**Data type:** Regexp_ + +### v +The string value to search. + +_**Data type:** String_ + +## Examples + +###### Filter by columns that contain matches to a regular expression +```js +import "regexp" + +data + |> filter(fn: (r) => + regexp.matchRegexpString( + r: /Alert\:/, + v: r.message + ) + ) +``` diff --git a/content/v2.0/reference/flux/functions/regexp/quotemeta.md b/content/v2.0/reference/flux/functions/regexp/quotemeta.md new file mode 100644 index 000000000..7a02a2f3e --- /dev/null +++ b/content/v2.0/reference/flux/functions/regexp/quotemeta.md @@ -0,0 +1,44 @@ +--- +title: regexp.quoteMeta() function +description: > + The `regexp.quoteMeta()` function escapes all regular expression metacharacters inside of a string. +menu: + v2_0_ref: + name: regexp.quoteMeta + parent: Regular expressions +weight: 301 +--- + +The `regexp.quoteMeta()` function escapes all regular expression metacharacters inside of a string. + +_**Output data type:** String_ + +```js +import "regexp" + +regexp.quoteMeta(v: ".+*?()|[]{}^$") + +// Returns "\.\+\*\?\(\)\|\[\]\{\}\^\$" +``` + +## Parameters + +### v +The string that contains regular expression metacharacters to escape. + +_**Data type:** String_ + +## Examples + +###### Escape regular expression meta characters in column values +```js +import "regexp" + +data + |> map(fn: (r) => ({ + r with + notes: r.notes, + notes_escaped: regexp.quoteMeta(v: r.notes) + }) + ) +``` diff --git a/content/v2.0/reference/flux/functions/regexp/replaceallstring.md b/content/v2.0/reference/flux/functions/regexp/replaceallstring.md new file mode 100644 index 000000000..04c7383f7 --- /dev/null +++ b/content/v2.0/reference/flux/functions/regexp/replaceallstring.md @@ -0,0 +1,59 @@ +--- +title: regexp.replaceAllString() function +description: > + The `regexp.replaceAllString()` function replaces all regular expression matches + in a string with a specified replacement. +menu: + v2_0_ref: + name: regexp.replaceAllString + parent: Regular expressions +weight: 301 +--- + +The `regexp.replaceAllString()` function replaces all regular expression matches +in a string with a specified replacement. + +_**Output data type:** String_ + +```js +import "regexp" + +regexp.replaceAllString(r: /a(x*)b/, v: "-ab-axxb-", t: "T") + +// Returns "-T-T-" +``` + +## Parameters + +### r +The regular expression used to search `v`. + +_**Data type:** Regexp_ + +### v +The string value to search. + +_**Data type:** String_ + +### t +The replacement for matches to `r`. + +_**Data type:** String_ + +## Examples + +###### Replace regular expression matches in string column values +```js +import "regexp" + +data + |> map(fn: (r) => ({ + r with + message: r.message, + updated_message: regexp.replaceAllString( + r: /cat|bird|ferret/, + v: r.message, + t: "dog" + ) + })) +``` diff --git a/content/v2.0/reference/flux/functions/regexp/splitregexp.md b/content/v2.0/reference/flux/functions/regexp/splitregexp.md new file mode 100644 index 000000000..28d25fdad --- /dev/null +++ b/content/v2.0/reference/flux/functions/regexp/splitregexp.md @@ -0,0 +1,41 @@ +--- +title: regexp.splitRegexp() function +description: > + The `regexp.splitRegexp()` function splits a string into substrings separated by + regular expression matches and returns an array of `i` substrings between matches. +menu: + v2_0_ref: + name: regexp.splitRegexp + parent: Regular expressions +weight: 301 +--- + +The `regexp.splitRegexp()` function splits a string into substrings separated by +regular expression matches and returns an array of `i` substrings between matches. + +_**Output data type:** Array of Strings_ + +```js +import "regexp" + +regexp.splitRegexp(r: /a*/, v: "abaabaccadaaae", i: 5) + +// Returns ["", "b", "b", "c", "cadaaae"] +``` + +## Parameters + +### r +The regular expression used to search `v`. + +_**Data type:** Regexp_ + +### v +The string value to search. + +_**Data type:** String_ + +### i +The number of substrings to return. + +_**Data type:** Integer_