Strings#

Meta: this page is mostly a method reference. Group by what you do with it; don't try to be exhaustive — link to Standard library reference for the full signatures.

Construction#

Conversion#

Inspection#

Strings have no .length / .isEmpty methods — those are list methods (Collections). Use the predicates below.

Case#

Trim and pad#

Split / replace#

Regex#

Regex methods — containsMatch, match, matchAll, replaceMatches, rewriteMatches, splitMatches — take a Regexp! pattern. A backtick template string auto-coerces to the Regexp scalar, so a pattern is usually written `\d+` (Go regexp/syntax). Full signatures are on Standard library reference.

Match object#

Returned by .match, and as the elements of .matchAll; a missing match is null. It only arises from these String/Regexp APIs, so it lives here rather than as a top-level stdlib module.

.captures: [String!]!

positional captures, with `captures[0]` corresponding to $1

"42-99".match(`(\d+)-(\d+)`).captures
.end: Int!

byte offset just past the end of the match

"x42y".match(`\d+`).end
.named: Map[String]!

named captures keyed by group name; a key reads as null if that group did not match, and is absent for an unknown name

"555-1212".match(`(?P<area>\d{3})-(\d{4})`).named["area"]
.start: Int!

byte offset of the match start in the source string

"x42y".match(`\d+`).start
.string: String!

the whole matched substring

"x42y".match(`\d+`).string