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

parse -r capture group naming inconsistency with standard regex. #12905

Open
CabalCrow opened this issue May 19, 2024 · 1 comment
Open

parse -r capture group naming inconsistency with standard regex. #12905

CabalCrow opened this issue May 19, 2024 · 1 comment
Labels
needs-triage An issue that hasn't had any proper look

Comments

@CabalCrow
Copy link

Describe the bug

When you use the internal command parse -r $regex* with a regex containing capture groups with no names (ex: (\w+)(\w)) it would name the groups capture0, capture1 and so on. This is inconsistent with the regex standard where capture group 0 is the full match, and individual capture group start from 1 onwards.

How to reproduce

  1. Run this command 'test' | parse -r '(\w+)(\w)'

Expected behavior

I expect the parse -r command to return capture groups naming starting with index 1 rather than 0.

Screenshots

No response

Configuration

key value
version 0.92.2
branch makepkg
commit_hash 2a08a18
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.77.1 (7cf61ebde 2024-03-27) (Arch Linux rust 1:1.77.1-2)
cargo_version cargo 1.77.1
build_time 2024-04-11 08:40:50 +00:00
build_rust_channel release
allocator mimalloc
features dataframe, default, sqlite, trash, which
installed_plugins

Additional context

No response

@CabalCrow CabalCrow added the needs-triage An issue that hasn't had any proper look label May 19, 2024
@fdncred
Copy link
Collaborator

fdncred commented May 19, 2024

I think this is due to the skip and capture{i}, probably should be capture{i+1}, but I haven't tested.

let columns = regex
.capture_names()
.skip(1)
.enumerate()
.map(|(i, name)| {
name.map(String::from)
.unwrap_or_else(|| format!("capture{i}"))
})
.collect::<Vec<_>>();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage An issue that hasn't had any proper look
Projects
None yet
Development

No branches or pull requests

2 participants