8000 GitHub - jogrue/regexhelpeR: Package to deal with regular expressions, mainly in dictionaries
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

jogrue/regexhelpeR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

regexhelpeR

A small R package to deal with regular expressions, mainly in dictionaries. This is used in multidictR and popdictR.

Install

This package requires the stringr package and can be installed from within R using devtools:

library(devtools)

# Install the socmedhelpeRs package from GitHub
devtools::install_github("jogrue/regexhelpeR")

Usage

# Loading the package
library("regexhelpeR")

# Some (greedy and one mixed) regular expressions
pat <- c("politic(.*)", "boy(s)?", "part(y|i)(.+)", "(.*)mixed(.*?)")

# Switch between lazy and greedy patterns
pat_switched <- switch_regex_greedy_lazy(pat)
pat
# [1] "politic(.*)"    "boy(s)?"        "part(y|i)(.+)"  "(.*)mixed(.*?)"
pat_switched
# [1] "politic(.*?)"   "boy(s)??"       "part(y|i)(.+?)" "(.*?)mixed(.*)"

# Turn all greedy patterns to lazy patterns
pat_lazy <- make_all_regex_lazy(pat)
pat_lazy
# [1] "politic(.*?)"    "boy(s)??"        "part(y|i)(.+?)"  "(.*?)mixed(.*?)"

# Turn all lazy patterns to greedy patterns
pat_greedy <- make_all_regex_greedy(pat_lazy)
pat_greedy
#[1] "politic(.*)"   "boy(s)?"       "part(y|i)(.+)" "(.*)mixed(.*)"

# Optimizations for running the dictionaries
pat_optim <- optimize_regex_patterns(pat_greedy)
pat_greedy
# [1] "politic(.*)"   "boy(s)?"       "part(y|i)(.+)" "(.*)mixed(.*)"
pat_optim
# [1] "\\bpolitic"          "\\bboy(s)?\\b"       "\\bpart(y|i)(.+)\\b" "mixed"  

Cite

Gründl, J. (2020). Populist ideas on social media: A dictionary-based measurement of populist communication. New Media & Society. Advance online publication. https://doi.org/10.1177/1461444820976970

Gründl, J. (2020). regexhelpeR (R package). https://github.com/jogrue/regexhelpeR

About

Package to deal with regular expressions, mainly in dictionaries

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0