Sample Header Ad - 728x90

Help with this non-capturing group with grep?

3 votes
4 answers
8447 views
I am new to GNU/Linux and regex. Recently I've been playing around trying to get to grips with regex. So far I feel I've got a pretty solid foundational understanding. I'm digging PCRE at the moment. This is the practice text file I'm playing about with: > 01234 567890 > > 01111-222111 > > 09876.543210 I can successfully match the numbers by doing something like this: (\d{5})[-.]?\s*?(\d{6}) Now I wanted to create a non-capturing group in order to miss out the first 5 digits and only match the last 6. So I guess I throw in (?:) to represent the non-capturing group followed by whatever I want to not be captured, right? So that would be (?:\d{5})[-.]?\s*?(\d{6}) I do that and in my terminal using grep -Po for PCRE and show output I'm still getting a full match as if the non-capturing group did not apply. Any guidance?
Asked by customcup (131 rep)
May 12, 2020, 12:37 AM
Last activity: May 19, 2020, 05:21 AM