UriPattern | R Documentation |
uri matcher
pattern
(character) pattern holder
regex
a logical
query_params
a list, or NULL
if empty
new()
Create a new UriPattern
object
UriPattern$new(pattern = NULL, regex_pattern = NULL)
pattern
(character) a uri, as a character string. if scheme is missing, it is added (we assume http)
regex_pattern
(character) a uri as a regex character string, see base::regex. if scheme is missing, it is added (we assume http)
A new UriPattern
object
matches()
Match a uri against a pattern
UriPattern$matches(uri)
uri
(character) a uri
a boolean
pattern_matches()
Match a URI
UriPattern$pattern_matches(uri)
uri
(character) a uri
a boolean
query_params_matches()
Match query parameters of a URI
UriPattern$query_params_matches(uri)
uri
(character) a uri
a boolean
extract_query()
Extract query parameters as a named list
UriPattern$extract_query(uri)
uri
(character) a uri
named list, or NULL
if no query parameters
add_query_params()
Add query parameters to the URI
UriPattern$add_query_params(query_params)
query_params
(list|character) list or character
nothing returned, updates uri pattern
to_s()
Print pattern for easy human consumption
UriPattern$to_s()
a string
clone()
The objects of this class are cloneable with this method.
UriPattern$clone(deep = FALSE)
deep
Whether to make a deep clone.
# trailing slash (z <- UriPattern$new(pattern = "http://foobar.com")) z$matches("http://foobar.com") # TRUE z$matches("http://foobar.com/") # TRUE # without scheme ## matches http by default: does not match https by default (z <- UriPattern$new(pattern = "foobar.com")) z$matches("http://foobar.com") # TRUE z$matches("http://foobar.com/") # TRUE z$matches("https://foobar.com") # FALSE z$matches("https://foobar.com/") # FALSE ## to match https, you'll have to give the complete url (z <- UriPattern$new(pattern = "https://foobar.com")) z$matches("https://foobar.com/") # TRUE z$matches("http://foobar.com/") # FALSE # default ports (z <- UriPattern$new(pattern = "http://foobar.com")) z$matches("http://foobar.com:80") # TRUE z$matches("http://foobar.com:80/") # TRUE z$matches("http://foobar.com:443") # TRUE z$matches("http://foobar.com:443/") # TRUE # user info - FIXME, not sure we support this yet (z <- UriPattern$new(pattern = "http://foobar.com")) z$matches("http://user:pass@foobar.com") # regex (z <- UriPattern$new(regex_pattern = ".+ample\\..")) z$matches("http://sample.org") # TRUE z$matches("http://example.com") # TRUE z$matches("http://tramples.net") # FALSE # add query parameters (z <- UriPattern$new(pattern = "http://foobar.com")) z$add_query_params(list(pizza = "cheese", cheese = "cheddar")) z z$pattern z$matches("http://foobar.com?pizza=cheese&cheese=cheddar") # TRUE z$matches("http://foobar.com?pizza=cheese&cheese=swiss") # FALSE # query parameters in the uri (z <- UriPattern$new(pattern = "https://httpbin.org/get?stuff=things")) z$add_query_params() # have to run this method to gather query params z$matches("https://httpbin.org/get?stuff=things") # TRUE z$matches("https://httpbin.org/get?stuff2=things") # FALSE # regex add query parameters (z <- UriPattern$new(regex_pattern = "https://foobar.com/.+/order")) z$add_query_params(list(pizza = "cheese")) z z$pattern z$matches("https://foobar.com/pizzas/order?pizza=cheese") # TRUE z$matches("https://foobar.com/pizzas?pizza=cheese") # FALSE # query parameters in the regex uri (z <- UriPattern$new(regex_pattern = "https://x.com/.+/order\\?fruit=apple")) z$add_query_params() # have to run this method to gather query params z$matches("https://x.com/a/order?fruit=apple") # TRUE z$matches("https://x.com/a?fruit=apple") # FALSE # any pattern (z <- UriPattern$new(regex_pattern = "stuff\\.com.+")) z$regex z$pattern z$matches("http://stuff.com") # FALSE z$matches("https://stuff.com/stff") # TRUE z$matches("https://stuff.com/apple?bears=brown&bats=grey") # TRUE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.