Skip to main content

String functions

4 functions on this page

String? find(String, String)

v1.2

Requires WDL v1.2. Given two String parameters input and pattern, searches for the occurrence of pattern within input and returns the first match or None if there are no matches. pattern is a [regular expression](https://en.wikipedia.org/wiki/Regular_expression) and is evaluated as a [POSIX Extended Regular Expression (ERE)](https://en.wikipedia.org/wiki/Regular_expression#POSIX_basic_and_extended). Note that regular expressions are written using regular WDL strings, so backslash characters need to be double-escaped. For example:

String
the input string to search.
String
the pattern to search for.
returns
The contents of the first match, or None if pattern does not match input.
Example
wdl
String? match = find("Hello, world!", "e..o");
# `match` now contains `ello`.

Boolean matches(String, String)

v1.2

Requires WDL v1.2. Given two String parameters input and pattern, tests whether pattern matches input at least once. pattern is a [regular expression](https://en.wikipedia.org/wiki/Regular_expression) and is evaluated as a [POSIX Extended Regular Expression (ERE)](https://en.wikipedia.org/wiki/Regular_expression#POSIX_basic_and_extended). To test whether pattern matches the entire input, make sure to begin and end the pattern with anchors. For example: Note that regular expressions are written using regular WDL strings, so backslash characters need to be double-escaped. For example:

String
the input string to search.
String
the pattern to search for.
returns
true if pattern matches input at least once, otherwise false.
Example
wdl
Boolean matches = matches("sample1234_R1.fastq", "_R1");
# `matches` now contains `true`.

Array[String] split(String, String)

v1.3

Requires WDL v1.3. Given the two String parameters input and delimiter, this function splits the input string on the provided delimiter and stores the results in a Array[String]. delimiter is a [regular expression](https://en.wikipedia.org/wiki/Regular_expression) and is evaluated as a [POSIX Extended Regular Expression (ERE)](https://en.wikipedia.org/wiki/Regular_expression#POSIX_basic_and_extended). Regular expressions are written using regular WDL strings, so backslash characters need to be double-escaped (e.g., "\\t").

String
the input string.
String
the delimiter to split on as a regular expression.
returns
The parts of the input string split by the delimiter. If the delimiter does not match anything in the input string, an array containing a single entry of the input string is returned.
Example
wdl
String input = "a,b,c"
Array[String] parts = split(input, ",")
# `parts` now contains `["a", "b", "c"]`.

String multiline = "line1\nline2\nline3"
Array[String] lines = split(multiline, "\\n")
# `lines` now contains `["line1", "line2", "line3"]`.

String sub(String, String, String)

Given three String parameters input, pattern, replace, this function replaces all non-overlapping occurrences of pattern in input by replace. pattern is a [regular expression](https://en.wikipedia.org/wiki/Regular_expression) and is evaluated as a [POSIX Extended Regular Expression (ERE)](https://en.wikipedia.org/wiki/Regular_expression#POSIX_basic_and_extended). Regular expressions are written using regular WDL strings, so backslash characters need to be double-escaped (e.g., "\\t").

String
the input string.
String
the pattern to search for.
String
the replacement string.
returns
the input string, with all occurrences of the pattern replaced by the replacement string.
Example
wdl
String chocolike = "I like chocolate when\nit's late"
String chocolove = sub(chocolike, "like", "love") #

# `chocolove` now contains `"I love chocolate when\nit's late"`.