help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ?: in regular expressions.


From: hancooper
Subject: Re: ?: in regular expressions.
Date: Mon, 23 Aug 2021 22:02:33 +0000

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Monday, August 23, 2021 9:58 PM, Dennis Williamson 
<dennistwilliamson@gmail.com> wrote:

> On Mon, Aug 23, 2021, 4:37 PM hancooper via <help-bash@gnu.org> wrote:
>
>> Am trying to understand what `?:` does in regular expressions. What is it 
>> good for?
>
>>
>
> It's a feature of PCRE. (quoting the MacOs pcrepattern man page) it causes 
> the subpattern (within the enclosing parentheses) to:
>
> "not do any capturing, and is not counted when computing the number of any 
> subsequent capturing subpatterns."
>
> So you could do alternation without capturing. Using the example from that 
> man page:
>
> the ((?:red|white) (king|queen))
>
> would capture white queen and queen given "the white queen" as input but it 
> wouldn't capture "white" by itself.
>
> I advise reading a lot of quality material on PCRE and regexes in general and 
> practicing and trying things. Also, my advice is that it's important to learn 
> when to not use regexes.
>
> regular-expressions.info is a good resource.
>
> Note that Bash does not support PCRE.
>
> ** Incidentally, one can support PCRE by using `grep -P`.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]