match_group {regreplaceR} | R Documentation |
Extract a Specific Named Group from a String
Description
This function extracts the value of a specific named group from a string using the provided regex pattern.
Usage
match_group(pattern, s, group_name, ignore.case = FALSE)
Arguments
pattern |
A character string containing the regex pattern with named groups. |
s |
A character string where the pattern will be searched. |
group_name |
The name of the group to extract from the match. |
ignore.case |
Logical. If TRUE, the pattern matching is case-insensitive. Default is FALSE. |
Value
The extracted value of the specified named group, or NULL if the group is not found.
Examples
pattern <- "(?P<name>\\w+) is (?P<age>\\d+)"
s <- "Jane is 25"
match_group(pattern, s, "name")
# [1] "Jane"
[Package regreplaceR version 0.1.0 Index]