Advantages of non-capturing groups

A non-capturing group lets us use the grouping inside a regular expression without changing the numbers assigned to the back references (explained in the next section). This can be very useful in building large and complex regular expressions.

Non-capturing groups also give us the flexibility to add or remove groups from a long regular expression with multiple groups. If we have to insert a new group or remove an existing group, then the numerical order changes for every group on the right-hand side of the new or removed group.

Using a non-capturing group instead of a capturing group saves memory, as the regular expression engine doesn't need to store groups in buffers, thus optimizing the overall regex execution. It is recommended to mark each group as non-capturing when we do not want to extract a grouped substring or refer to them anywhere in the regular expression.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.89.30