praw1: Pattern (or Pseudo) raw: Approximate Python-like 'raw'...

Description Usage Arguments Details Value See Also Examples

Description

Pattern (or Pseudo) raw: Approximate Python-like 'raw' Strings (with warnings)

Usage

1
praw1(pat, cesc = "`")

Arguments

pat

a string or character vector

cesc

a single character(default ') to be substituted by double \ in the pattern where any cescs appeared on input. Note this warns if 'cesc' is not a single character or if it is the special set: "([.|)\^+$*?:]"

Details

Literal occurrences of characters such as ([.|)\^+$*?:] often need to be escaped in regular expression patterns. This makes them look very different than e.g. raw string patterns. Thus, the equivalent of Python's pyPat= r'\(\s*\w+\s*\)' would have to look like: rPat <- "\\(\\s*\\w+\\s*\\)". With praw() we can instead use erPat <- ('`(`s*`w+`s*`)') To match a literal single backslash in a string, pat <- praw('``', '`' ) is necessary, generating pat= '\\'.

Value

the pattern with the 'cesc' character replaced by two backslashes. See details.

See Also

praw

Examples

1
2
3
4
5
6
7
praw1('`(`s*`w+`s*`)') == "\\(\\s*\\w+\\s*\\)"

# Replace a\\b with a:b

gsub(praw1('%%%%','%'), ":", "a\\\\b")
# or
gsub(praw("\\`\\```"), ":", "a\\\\b")

tnearey/nutils documentation built on May 8, 2019, 12:50 p.m.