class Regex::CapturingGroup
An association between a capture variable and an expression the subject text in the same serial arrangement
Attributes
id[R]
The capture variable id. It is a Fixnum when the capture group gets a sequence number, a String when it is an user-defined name
no_backtrack[R]
When true, then capturing group forbids backtracking requests from its parent expression.
Public Class Methods
new(aChildExpression, theId = nil, noBacktrack = false)
click to toggle source
Constructor. @param aChildExpression[ Regex::Expression]
A sub-expression to match. When successful the matching text is assigned to the capture variable.
@param theId [String] The id of the capture variable. @param noBacktrack [Boolean] A flag that specifies whether the capturing
group forbids backtracking requests from its parent expression.
Calls superclass method
# File lib/regex/capturing_group.rb, line 29 def initialize(aChildExpression, theId = nil, noBacktrack = false) super(aChildExpression) @id = theId @no_backtrack = noBacktrack end
Public Instance Methods
named?()
click to toggle source
Return true iff the capturing group has a name
# File lib/regex/capturing_group.rb, line 36 def named? id.kind_of?(String) end
to_str()
click to toggle source
Conversion method re-definition. Purpose: Return the String representation of the captured expression.
# File lib/regex/capturing_group.rb, line 42 def to_str prefix = named? ? "?<#{id}>" : '' atomic = no_backtrack ? '?>' : '' if child.is_a?(Regex::NonCapturingGroup) # Minor optimization suffix = child.child.to_str else suffix = child.to_str end "(#{atomic}#{prefix}#{suffix})" end