Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extracting a regex that might have multiple matches #345

Closed
tcovert opened this issue Aug 18, 2017 · 1 comment
Closed

extracting a regex that might have multiple matches #345

tcovert opened this issue Aug 18, 2017 · 1 comment

Comments

@tcovert
Copy link

tcovert commented Aug 18, 2017

I see in the code for extract that only the first match of a regular expression is captured. Is there a sensible way to do what extract does on a column in which one expects the regular expression to match multiple times? Here's an example of what I am trying to accomplish:

t <- as_tibble(list(z = c("a1", "a2b3", "a4b5c6")))
long_t <- extract(t, z, c("y"), regex = regex("(\\d)"), matchID = c("matchID"), remove = FALSE)

I realize the matchID keyword doesn't actually exist, but if it did, it would give us the following for long_t:

# A tibble: 6 x 3
      z     y     matchID
  <chr>     <chr>   <dbl>
1    a1         1       1
2    a2b3       2       1
3    a2b3       3       2
4    a4b5c6     4       1
5    a4b5c6     5       2
6    a4b5c6     6       3
@hadley
Copy link
Member

hadley commented Nov 15, 2017

This sort of question is a better fit for https://community.rstudio.com. Do you mind asking it over there? (You might want to read https://www.tidyverse.org/help/ first to maximise your chances of getting a good answer)

@hadley hadley closed this as completed Nov 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants