Escape whitespace in regular expression patterns
Source:R/jambio-design.R
escapeWhitespaceRegexp.RdEscape whitespace in regular expression patterns
Arguments
- x
character vector containing a regular expression pattern, or a character value that should be converted to a regular expression pattern.
- whitespace
character vector
length=1containing whitespace characters, for example" _"will define space" "and underscore"_"both as whitespace characters.- maxN
integer value for maximum iterations of the substitution, unfortunately the regular expression logic only matches once per iteration per string.
- ...
additional arguments are ignored.
Details
This function is intended to test for unescaped whitespace characters in a regular expression pattern match string, and replace them with escaped whitespace characters, possibly expanding the allowed whitespace characters in the process.
See also
Other Internal utility functions:
combineGRcoverage(),
compressPolygonM(),
df2colorSub(),
dfWide2segments(),
factor2label(),
geomean(),
intercalate(),
internal_junc_score(),
jamGeomean(),
list2im(),
shrinkMatrix(),
simplifyXY(),
stackJunctions(),
strsplitOrdered()
Examples
x <- c("one two three", "one[ ]two three", "one[ 12] two three");
escapeWhitespaceRegexp(x);
#> [1] "one[_ ]+two[_ ]+three" "one[ ]two[_ ]+three"
#> [3] "one[ 12][_ ]+two[_ ]+three"
# side-by-side summary of input and output
data.frame(input=paste0('"', x, '"'),
output=paste0('"', escapeWhitespaceRegexp(x), '"'))
#> input output
#> 1 "one two three" "one[_ ]+two[_ ]+three"
#> 2 "one[ ]two three" "one[ ]two[_ ]+three"
#> 3 "one[ 12] two three" "one[ 12][_ ]+two[_ ]+three"