(?:)
It is a valid ruby regular expression, could anyone tell me what it means?
Thanks
(?:)
It is a valid ruby regular expression, could anyone tell me what it means?
Thanks
It will not capture the part of the matching string in a backreference (i.e \1).
This is an empty, non-capturing group. It has no meaning in this case and can be dropped.
Like others have said, it's used as the non-capturing syntax for a regex, but, it's also valid ruby syntax outside of a regex.
In ruby ?:
is the integer value for the colon character:
% irb
irb> ?:
=> 58
irb ":"[0]
=> 58
Adding parenthesis doesn't change the value: (?:) == ?:
When you add spaces (? :
), it's the ternary operator, which is essentially shorthand for if/then/else in ruby, so the statement ( bool ? truish : falsy )
is equivalent to
if bool then
truish
else
falsy
end