Class: Java::java::util::regex::Matcher

Inherits:
Object
  • Object
show all
Defined in:
core/src/main/ruby/jruby/java/java_ext/java.util.regex.rb

Overview

Note:

Only explicit (or customized) Ruby methods are listed, instances will have all of their Java methods available.

java.util.regex.Matcher represents a Java regex `Pattern` match, customized to quack like Ruby's `MatchData`.

See Also:

Instance Method Summary (collapse)

Instance Method Details

- (Array) [](*args)

Matcher acts like an array and its capture elements might be accessed.

Examples:

pattern = java.util.regex.Pattern.compile("(.)(.)(\\d+)(\\d)")
matcher = pattern.match('THX1138.')
expect( m[0] ).to eq 'HX1138'
expect( m[1, 2] ).to eq ['H', 'X']
expect( m[1..3] ).to eq ['H', 'X', '113']

Returns:

  • (Array)

See Also:



78
79
80
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.regex.rb', line 78

def [](*args)
  # stub implemented in org.jruby.javasupport.ext.JavaUtilRegex.java
end

- (Integer) begin(n)

Note:

Named captures referencing is not available on Java 7.

Returns the offset of the start of the n-th element of the match array in the string.

Examples:

pattern = java.util.regex.Pattern.compile("(.)(.)(\\d+)(\\d)")
matcher = pattern.match('THX1138.')
expect( matcher.begin(0) ).to eq 1
expect( matcher.begin(2) ).to eq 2

Parameters:

  • n

    can be a string or symbol to reference a named capture

Returns:

  • (Integer)

See Also:



116
117
118
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.regex.rb', line 116

def begin(n)
  # stub implemented in org.jruby.javasupport.ext.JavaUtilRegex.java
end

- (Array) captures

Returns an array of captures.

pattern = java.util.regex.Pattern.compile("(.)(.)(\\d+)(\\d)")
pattern.match('THX1138.').captures # ['H', 'X', '113', '8']

Returns:

  • (Array)

See Also:



65
66
67
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.regex.rb', line 65

def captures
  # stub implemented in org.jruby.javasupport.ext.JavaUtilRegex.java
end

- (Integer) end(n)

Note:

Named captures referencing is not available on Java 7.

Returns the offset of the character immediately following the end of the n-th element of the match array in the string.

Examples:

pattern = java.util.regex.Pattern.compile("(.)(.)(\\d+)(\\d)")
matcher = pattern.match('THX1138.')
expect( matcher.begin(0) ).to eq 7
expect( matcher.begin(2) ).to eq 3

Parameters:

  • n

    can be a string or symbol to reference a named capture

Returns:

  • (Integer)

See Also:



131
132
133
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.regex.rb', line 131

def end(n)
  # stub implemented in org.jruby.javasupport.ext.JavaUtilRegex.java
end

- (Array) offset(n)

Returns the offset of the character immediately following the end of the n-th element of the match array in the string.

Examples:

pattern = java.util.regex.Pattern.compile("(.)(.)(\\d+)(\\d)")
matcher = pattern.match('THX1138.')
expect( m.offset(0) ).to eq [1, 7]
expect( m.offset(4) ).to eq [6, 7]

pattern = java.util.regex.Pattern.compile("(?<foo>.)(.)(?<bar>.)")
matcher = pattern.match('hoge')
expect( m.offset(:bar) ).to eq [2, 3]

Parameters:

  • n

    can be a string or symbol to reference a named capture

Returns:

  • (Array)

See Also:



149
150
151
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.regex.rb', line 149

def offset(n)
  # stub implemented in org.jruby.javasupport.ext.JavaUtilRegex.java
end

- (String) post_match

Returns the portion of the original string after the current match.

Returns:

  • (String)


161
162
163
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.regex.rb', line 161

def post_match
  # stub implemented in org.jruby.javasupport.ext.JavaUtilRegex.java
end

- (String) pre_match

Returns the portion of the original string before the current match.

Returns:

  • (String)


155
156
157
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.regex.rb', line 155

def pre_match
  # stub implemented in org.jruby.javasupport.ext.JavaUtilRegex.java
end

- (Java::java::util::regex::Pattern) regexp

Returns:

Since:

  • 9.1



52
53
54
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.regex.rb', line 52

def regexp
  # stub implemented in org.jruby.javasupport.ext.JavaUtilRegex.java
end

- (Integer) size Also known as: length

Returns the number of elements in the match array.

Examples:

pattern = java.util.regex.Pattern.compile("(.)(.)(\\d+)(\\d)")
pattern.match('THX1138.').size # 5

Returns:

  • (Integer)


100
101
102
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.regex.rb', line 100

def size
  # stub implemented in org.jruby.javasupport.ext.JavaUtilRegex.java
end

- (Object) string



56
57
58
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.regex.rb', line 56

def string
  # stub implemented in org.jruby.javasupport.ext.JavaUtilRegex.java
end

- (Array) to_a

Returns the array of matches.

Examples:

pattern = java.util.regex.Pattern.compile("(.)(.)(\\d+)(\\d)")
pattern.match('THX1138.').captures # ['HX1138', 'H', 'X', '113', '8']

Returns:

  • (Array)


87
88
89
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.regex.rb', line 87

def to_a
  # stub implemented in org.jruby.javasupport.ext.JavaUtilRegex.java
end

- (Object) values_at(*args)



91
92
93
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.regex.rb', line 91

def values_at(*args)
  # stub implemented in org.jruby.javasupport.ext.JavaUtilRegex.java
end