Skip to content

Instantly share code, notes, and snippets.

@lauratboyer
Created July 24, 2013 18:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lauratboyer/6073009 to your computer and use it in GitHub Desktop.
Save lauratboyer/6073009 to your computer and use it in GitHub Desktop.
This function allows you to extract the part of the string that matches the regular expression given as input. For instance, if you have species names and want to extract the gender only, you would type: getmatch("Echinometra mathaei", "^\\w+") # Echinometra
getmatch <<- function(x,str2match,...) {
unlist(regmatches(x,regexpr(str2match,x,...))) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment