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

[Question] Which regex syntax does sd use? #168

Closed
TornaxO7 opened this issue Aug 23, 2022 · 3 comments
Closed

[Question] Which regex syntax does sd use? #168

TornaxO7 opened this issue Aug 23, 2022 · 3 comments

Comments

@TornaxO7
Copy link

Hello! I'm playing a little bit with sd and tried to execute the following:

echo "some text 123" | sd -p 'some text (?<numbers>{3})' '${numbers}'

I expected to get the output 123 but I'm getting

Error: invalid regex regex parse error:
    some text (?<numbers>{3})
                ^
error: unrecognized flag

instead. According to this cheatsheet I can use

(?<name>...) | Named Capturing Group

for a named group capturing but it doesn't work for sd. Where can I look up the regex syntax which sd uses?

@TornaxO7 TornaxO7 changed the title [Question] Which regex syntax is used? [Question] Which regex syntax does sd use? Aug 23, 2022
@pinage404
Copy link

Hello,

I just tried this

echo "some text 123" | sd --preview 'some text (?P<numbers>[0-9]{3})' 'with named capture group : ${numbers} ; with counted capture group : $1'

And it outputs this :

with named capture group : 123 ; with counted capture group : 123

@pinage404
Copy link

sd uses the regex crate

sd/Cargo.toml

Line 15 in ac76b2d

regex = "1.4.3"

which show examples for named capture group

https://github.com/rust-lang/regex/blob/159a63c85eb77ec321301bc4c4ebfb90343edc2b/README.md?plain=1#L37

@TornaxO7
Copy link
Author

TornaxO7 commented Aug 26, 2022

Oh god, I just needed the --preview arg.... thank you!

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