match_near: Generate a Regular Expression for Finding Two Patterns...

Description Usage Arguments Details Value Examples

View source: R/match_near.R

Description

Generate a Regular Expression for Finding Two Patterns Occurring Near Each Other

Usage

1
match_near(pattern1, pattern2, max_distance = 250)

Arguments

pattern1, pattern2

Two character strings each containing a word or a stringi-search-regex to be found near each other.

max_distance

The maximum number of words intervening between the two specified patterns

Details

match_near is a convenience function that creates a regular expression pattern for finding if two words (or other regular expression patterns) occur within a specified number of words of each other

Value

A regular expression pattern

Examples

1
2
3
4
5
6
7
colors <- "red|blue|yellow"
sentences <- c("The car parked by their house was red",
               "The yellow cat enjoys the sun atop the car's roof",
               "The blue city bus passed right by the stopped car")
stringr::str_detect(sentences, match_near(colors, "car", 5))
stringr::str_detect(sentences, match_near(colors, "car|bus", 5))
stringr::str_detect(sentences, match_near(colors, "car", 10))

mariolaespinosa/historicalnetworks documentation built on Feb. 9, 2022, 12:31 p.m.