I have a regex that looks like this
/^(?:\w+\s)*(\w+)$*/
What is the ?:
?
It indicates that the subpattern is a non-capture subpattern. That means whatever is matched in (?:\w+\s) , even though it's enclosed by () it won't appear in the list of matches, only (\w+) will.
Definition and Usage The \f metacharacter matches form feed characters.
It indicates that the subpattern is a non-capture subpattern. That means whatever is matched in (?:\w+\s)
, even though it's enclosed by ()
it won't appear in the list of matches, only (\w+)
will.
You're still looking for a specific pattern (in this case, a single whitespace character following at least one word), but you don't care what's actually matched.
It means only group but do not remember the grouped part.
By default (
)
tells the regex engine to remember the part of the string that matches the pattern between it. But at times we just want to group a pattern without triggering the regex memory, to do that we use (?:
in place of (
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With