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
None
ifpattern
does 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
true
ifpattern
matchesinput
at least once, otherwisefalse
.
Example
Boolean matches = matches("sample1234_R1.fastq", "_R1");
# `matches` now contains `true`.
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"`.