Method: Regexp#arity
- Defined in:
- lib/core/facets/regexp/arity.rb
#arity ⇒ Object
Returns the number of backreferencing subexpressions.
/(a)(b)(c)/.arity #=> 3
/(a(b(c)))/.arity #=> 3
Note that this is not perfect, especially with regards to x and embedded comments.
CREDIT: Trans
13 14 15 |
# File 'lib/core/facets/regexp/arity.rb', line 13 def arity source.scan( /(?!\\)[(](?!\?[#=:!>-imx])/ ).length end |