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

Underscore in named group matching #506

Closed
DSLituiev opened this issue Mar 28, 2023 · 2 comments
Closed

Underscore in named group matching #506

DSLituiev opened this issue Mar 28, 2023 · 2 comments

Comments

@DSLituiev
Copy link

I am trying to match a named group and running into a behaviour that does not seem to be properly documented.

filnames = c("a","b", "c")

pattern_regex <- (?<my_variable>[a-zA_\\-]+)"

str_match(filnames, pattern_regex)
Error in stri_match_first_regex(string, pattern, opts_regex = opts(pattern)) : 
  Invalid capture group name. (U_REGEX_INVALID_CAPTURE_GROUP_NAME, context= ...

There is no documentation that says underscores are unsupported, and given it's a common practice in other languages, like python re, I assumed it should have worked. The error message is not helpful either

@gagolews
Copy link
Contributor

Please see the documentation of the underlying stringi package:

https://stringi.gagolewski.com/rapi/about_search_regex.html:

(?<name>...): Named capture group, where name (enclosed within the angle brackets) is a sequence like [A-Za-z][A-Za-z0-9]*

@hadley hadley closed this as completed Aug 4, 2023
@hadley
Copy link
Member

hadley commented Aug 4, 2023

Thanks @gagolews!

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

3 participants