Merge pull request #276 from influxdata/flux/regexp-functions
Flux regular expression functionspull/282/head
commit
263439df6b
|
@ -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" >}}
|
|
@ -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
|
||||
)
|
||||
})
|
||||
)
|
||||
```
|
|
@ -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)
|
||||
})
|
||||
)
|
||||
```
|
|
@ -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
|
||||
)
|
||||
})
|
||||
)
|
||||
```
|
|
@ -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)
|
||||
})
|
||||
)
|
||||
```
|
|
@ -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
|
||||
)
|
||||
)
|
||||
```
|
|
@ -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)
|
||||
})
|
||||
)
|
||||
```
|
|
@ -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"
|
||||
)
|
||||
}))
|
||||
```
|
|
@ -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_
|
Loading…
Reference in New Issue