The question mark and the colon after the opening round bracket are the special syntax that you can use to tell the regex engine that this pair of brackets should not create a backreference. If you do not use the backreference, you can optimize this regular expression into Set(?:Value)?. In the second case, the first backreference will contain Value. In the first case, the first backreference will be empty, because it did not match anything. The regex Set(Value)? matches Set or SetValue. If you do not use the backreference, you can speed things up by using non-capturing parentheses, at the expense of making your regular expression slightly harder to read. Remembering part of the regex match in a backreference, slows down the regex engine because it has more work to do. That is, unless you use non-capturing parentheses. A backreference stores the part of the string matched by the part of the regular expression inside the parentheses. Round Brackets Create a Backreferenceīesides grouping part of a regular expression together, round brackets also create a "backreference". Square brackets define a character class, and curly braces are used by a special repetition operator. Note that only round brackets can be used for grouping. I have already used round brackets for this purpose in previous topics throughout this tutorial. a repetition operator, to the entire group. This allows you to apply a regex operator, e.g. Get your own copy of RegexBuddy nowīy placing part of a regular expression inside round brackets or parentheses, you can group that part of the regular expression together. Developed by the author of this web site, RegexBuddy makes learning and using regular expressions easier than ever. Easily create and understand regular expressions today.Ĭompose and analyze regex patterns with RegexBuddy's easy-to-grasp regex blocks and intuitive regex tree, instead of or in combination with the traditional regex syntax.