re_match {re} | R Documentation |
Match a pattern at the start of a string
Description
re_match
checks whether each element of a character vector matches a specified pattern (regular
expression) at the start. If the provided pattern is not already a compiled pattern object, it compiles it using
re_compile
. The function ensures that the matching occurs at the beginning of the string.
Usage
re_match(pattern, string, ...)
Arguments
pattern |
A regular expression pattern or a compiled pattern object. |
string |
A character vector where each element is a string to be matched against the pattern at the beginning. |
... |
Arguments passed on to
|
Value
A list where each element is a character vector containing the match found at the start of the corresponding
element of string
, or character(0)
if there is no match at the start.
See Also
Python re.match() equivalent functionality documentation
Examples
pattern <- re_compile("\\d{3}")
re_match(pattern, "123abc")
re_match("abc", "xyzabc")