2

This regex is supposed to match any numbers (real or integer - no scientific notation). However, I am not sure what is the use of '?:' inside the parentheses. Could anyone explain this along with some examples? Thank you very much.

Carlos Yip
  • 41
  • 3

1 Answers1

2

In the regex

?\d+(?:\.\d+)?

The ?: quantity inside the group in parenthesis instructs the regex engine to not capture the group, which it otherwise would.

By not capturing the quantity in parenthesis, the capture group available (which should be the first one, and the entire expression) would just be the digits occurring before the decimal point, should the number have a fractional component.

Tim Biegeleisen
  • 387,723
  • 20
  • 200
  • 263