path.extensionRegExp: Create a Regular Expression that can match a File Name versus...

Description Usage Arguments Value Examples

View source: R/extensionRegExp.R

Description

For a given list extensions of file extensions, e.g., c("txt", "csv") or just a single file extension, this function creates a regular expression while will match a file path that ends in any of the extensions (with a leading ".").

Usage

1
path.extensionRegExp(extensions, before.extension = NULL)

Arguments

extensions

either a single string or array of strings, each holding a file extension

before.extension

a string required to occur immediately before the file extension

Value

the regular expression which will match them

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
exp <- path.extensionRegExp(c("html", "jpg"))
exp
# [1] "^.*\\.(html|jpg)$"
length(grep(exp, "hellojpg")) > 0L
# [1] FALSE
length(grep(exp, "hello.jpg")) > 0L
# [1] TRUE
length(grep(exp, "hello.html")) > 0L
# [1] TRUE
length(grep(exp, "hellohtml")) > 0L
# [1] FALSE
length(grep(exp, "hello.htm")) > 0L
# [1] FALSE
length(grep(exp, "hello.html.txt")) > 0L
# [1] FALSE

thomasWeise/utilizeR documentation built on May 30, 2019, 11:48 a.m.