Class: PCRE2::Regexp
- Inherits:
-
Object
- Object
- PCRE2::Regexp
- Defined in:
- lib/pcre2/regexp.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#initialize(pattern, *options) ⇒ Regexp
constructor
A new instance of Regexp.
-
#jit! ⇒ Object
Compiles the Regexp into a JIT optimised version.
- #match(str, pos = nil) ⇒ Object
- #named_captures ⇒ Object
- #names ⇒ Object
Constructor Details
#initialize(pattern, *options) ⇒ Regexp
Returns a new instance of Regexp.
4 5 6 7 |
# File 'lib/pcre2/regexp.rb', line 4 def initialize(pattern, *) @source = pattern @pattern_ptr = PCRE2::Lib.compile_pattern(pattern, ) end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
2 3 4 |
# File 'lib/pcre2/regexp.rb', line 2 def source @source end |
Instance Method Details
#jit! ⇒ Object
Compiles the Regexp into a JIT optimised version. Returns whether it was successful
10 11 12 13 14 |
# File 'lib/pcre2/regexp.rb', line 10 def jit! = PCRE2::PCRE2_JIT_COMPLETE | PCRE2::PCRE2_JIT_PARTIAL_SOFT | PCRE2::PCRE2_JIT_PARTIAL_HARD PCRE2::Lib.pcre2_jit_compile_8(pattern_ptr, ) == 0 end |
#match(str, pos = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/pcre2/regexp.rb', line 16 def match(str, pos = nil) result_count, match_data_ptr = PCRE2::Lib.match(@pattern_ptr, str, position: pos) if result_count == 0 nil else pairs = PCRE2::Lib.get_ovector_pairs(match_data_ptr, result_count) PCRE2::MatchData.new(self, str, pairs) end end |
#named_captures ⇒ Object
28 29 30 |
# File 'lib/pcre2/regexp.rb', line 28 def named_captures @named_captures ||= PCRE2::Lib.named_captures(pattern_ptr) end |
#names ⇒ Object
32 33 34 |
# File 'lib/pcre2/regexp.rb', line 32 def names named_captures.keys end |