Open dvas0004 opened 5 years ago
When grouping expressions together we need to use brackets. For example:
(abc|123)
will match "abc" or "123". However, what if we would not like to include these in our matched groups? The answer is to use a non-matching group:
(?:abc|123)
note the use of:
(?:.*some_regex.*)
Example of the difference:
Without using a non-matching group we end up with 2 matching groups:
If this is not ideal and instead we use a non-matching group:
Then number of matching groups is reduced to only what we're interested in:
Note how we have only one matching group per line in the above screenshot compared to the two groups we had before
When grouping expressions together we need to use brackets. For example:
will match "abc" or "123". However, what if we would not like to include these in our matched groups? The answer is to use a non-matching group:
note the use of:
Example of the difference:
Without using a non-matching group we end up with 2 matching groups:
If this is not ideal and instead we use a non-matching group:
Then number of matching groups is reduced to only what we're interested in:
Note how we have only one matching group per line in the above screenshot compared to the two groups we had before