String Functions
find 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 and is evaluated as a POSIX Extended Regular Expression (ERE).
Note that regular expressions are written using regular WDL strings, so backslash characters need to be double-escaped. For example:
String? first_match = find("hello\tBob", "\\t")Signatures
String? find(String, String)Parameters
String: the input string to search.String: the pattern to search for.
Returns
- The contents of the first match, or
Noneifpatterndoes not matchinput.
Example
String? match = find("Hello, world!", "e..o");
# `match` now contains `ello`.matches Requires WDL v1.2
Given two String parameters input and pattern, tests whether pattern matches input at least once. pattern is a regular expression and is evaluated as a POSIX Extended Regular Expression (ERE).
To test whether pattern matches the entire input, make sure to begin and end the pattern with anchors. For example:
Boolean full_match = matches("abc123", "^a.+3$")Note that regular expressions are written using regular WDL strings, so backslash characters need to be double-escaped. For example:
Boolean has_tab = matches("hello\tBob", "\\t")Signatures
Boolean matches(String, String)Parameters
String: the input string to search.String: the pattern to search for.
Returns
trueifpatternmatchesinputat least once, otherwisefalse.
Example
Boolean matches = matches("sample1234_R1.fastq", "_R1");
# `matches` now contains `true`.split 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 and is evaluated as a POSIX Extended Regular Expression (ERE). Regular expressions are written using regular WDL strings, so backslash characters need to be double-escaped (e.g., "\\t").
Signatures
Array[String] split(String, String)Parameters
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
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"]`.sub
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 and is evaluated as a POSIX Extended Regular Expression (ERE). Regular expressions are written using regular WDL strings, so backslash characters need to be double-escaped (e.g., "\\t").
Signatures
String sub(String, String, String)Parameters
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
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"`.