Non Capturing Groups

Expressions can contain a lot of groups which you weren't interested in matching on. It is possible to tell .net not to capture these by placing a ?: at the beginning of the group. Apparently limiting the number of capturing groups has a positive increase on performance.

The following expression will return one group, containing the entire match:

"(The door was (?:open|closed))"

This expression will also return one group, this time containing the state of the door; open or closed

"(?:The door was (open|closed))"
Author Paul Hayman

Paul is the COO of kwiboo ltd and has more than 20 years IT consultancy experience. He has consulted for a number of blue chip companies and has been exposed to the folowing sectors: Utilities, Telecommunications, Insurance, Media, Investment Banking, Leisure, Legal, CRM, Pharmaceuticals, Interactive Gaming, Mobile Communications, Online Services.

Paul is the COO and co-founder of kwiboo ( and is also the creator of GeekZilla.

Add Comment


Your comment has been received and will be shown once it passes moderation.