grep

Table of Contents

Function

grep — search strings inside of values

Synopsis

grep(<pattern> [, e: any]) -> bool

Description

The grep function searches all of the strings in its input value e (or this if e is not given) using the <pattern> argument, which can be a regular expression, glob pattern, or string. If the pattern matches for any string, then the result is true. Otherwise, it is false.

Note that string matches are case insensitive while regular expression and glob matches are case sensitive. In a forthcoming release, case sensitivity will be a expressible for all three pattern types.

The entire input value is traversed:

  • for records, each field name is traversed and each field value is traversed or descended if a complex type,
  • for arrays and sets, each element is traversed or descended if a complex type, and
  • for maps, each key and value is traversed or descended if a complex type.

Examples

Reach into nested records

grep("baz")
{foo:10}{bar:{s:"baz"}}
Loading...

It only matches string fields

grep("10")
{foo:10}{bar:{s:"baz"}}
Loading...

Match a field name

grep("foo")
{foo:10}{bar:{s:"baz"}}
Loading...

Regular expression

grep(/foo|baz/)
{foo:10}{bar:{s:"baz"}}
Loading...

Glob with a second argument

grep(b*, s)
{s:"bar"}{s:"foo"}{s:"baz"}{t:"baz"}
Loading...
Next: grok

SuperDB