class Regex::Lookaround
Lookaround
is a zero-width assertion just like the start and end of line anchors. The difference is that lookarounds will actually match characters, but only return the result of the match: match or no match. That is why they are called “assertions”. They do not consume characters from the subject, but only assert whether a match is possible or not.
Attributes
The “direction” of the lookaround. Can be ahead or behind. It specifies the relative position of the expression to match compared to the current 'position' in the subject text.
The kind indicates whether the assertion is positive (succeeds when there is a match) or negative (assertion succeeds when there is NO match).
Public Class Methods
Constructor.
- assertedExpression
-
A sub-expression to match.
- theDir
-
One of the following values: [ :ahead, :behind ]
- theKind
-
One of the following values: [ :positive, :negative ]
# File lib/regex/lookaround.rb, line 34 def initialize(assertedExpression, theDir, theKind) super(assertedExpression) @dir = theDir @kind = theKind end
Public Instance Methods
Conversion method re-definition. Purpose: Return the String representation of the captured expression.
# File lib/regex/lookaround.rb, line 42 def to_str dir_syntax = (dir == :ahead) ? '' : '<' kind_syntax = (kind == :positive) ? '=' : '!' result = "(?#{dir_syntax}#{kind_syntax}#{child.to_str})" return result end