blob: ffbf8923dae1e60afb1f3d037312ece40b692f89 [file] [log] [blame]
Marcel van Lohuizenf3cd8482019-09-12 15:04:04 +02001cue eval -i regexp.cue
2cmp stdout expect-stdout-cue
3
4-- frontmatter.toml --
5title = "Regular expressions"
6description = ""
7
8-- text.md --
9The `=~` and `!~` operators can be used to check against regular expressions.
10
11The expression `a =~ b` is true if `a` matches `b`, while
12`a !~ b` is true if `a` does _not_ match `b`.
13
14Just as with comparison operators, these operators may be used
15as unary versions to define a set of strings.
16
17-- regexp.cue --
18a: "foo bar" =~ "foo [a-z]{3}"
19b: "maze" !~ "^[a-z]{3}$"
20
21c: =~"^[a-z]{3}$" // any string with lowercase ASCII of length 3
22
23d: c
24d: "foo"
25
26e: c
27e: "foo bar"
28
29-- expect-stdout-cue --
30a: true
31b: true
32c: =~"^[a-z]{3}$"
33d: "foo"
34e: _|_ // invalid value "foo bar" (does not match =~"^[a-z]{3}$")