情報学部 | 菅沼ホーム | 目次 | 索引 |
p "abcdefyycxxk".match(/(c..)\w+(c..)/)[0] # => "cdefyycxx" p "abcdefyycxxk".match(/(c..)\w+(c..)/)[1] # => "cde" p "abcdefyycxxk".match(/(c..)\w+(c..)/)[2] # => "cxx"
p "abcdfyycxkkczy".match(/(c.)\w+(c.)\w+(c.)/)[1..2] # => ["cd", "cx"]
p "abcdfyycxkkczy".match(/(c.)\w+(c.)\w+(c.)/)[1,2] # => ["cd", "cx"]
p "abcdfyycxkkczy".match(/(c.)\w+(c.)\w+(c.)/).begin(2) # => 7
p "abcdfyycxkkczy".match(/(c.)\w+(c.)\w+(c.)/).end(2) # => 9
p "abcdfyycxkkczy".match(/(c.)\w+(c.)\w+(f.)?/).captures # => ["cd", "cz", nil] p "abcdfyycxkkczy".match(/(c.)\w+(c.)\w+(f.)?/).to_a # => ["cdfyycxkkczy", "cd", "cz", nil]
p "abcdef".match(/c./).length # => 1 p "abcdfyycxkkczy".match(/(c.)\w+(c.)\w+(f.)?/).length # => 4
p "abcdfyycxkkczy".match(/(c.)\w+(c.)\w+(c.)/).offset(2) # => [7, 9]
p "abcdfyycxkk".match(/(c.)\w+(c.)/).pre_match # => "ab" p "abcdfyycxkk".match(/(c.)\w+(c.)/).post_match # => "kk"
p "abcdfyycxkk".match(/(c.)\w+(c.)/).pre_match # => "ab" p "abcdfyycxkk".match(/(c.)\w+(c.)/).post_match # => "kk"
p "a1b23c456d".match(/(\d+)\w(\d+)\w(\d+)/).to_a # => ["1b23c456", "1", "23", "456"] p "a1b23c456d".match(/(\d+)\w(\d+)\w(\d+)/).select { |s| s.length < 3 } # => ["1", "23"]
p "abcdfyycxkkczy".match(/(c.)\w+(c.)\w+(f.)?/).captures # => ["cd", "cz", nil] p "abcdfyycxkkczy".match(/(c.)\w+(c.)\w+(f.)?/).to_a # => ["cdfyycxkkczy", "cd", "cz", nil]
p "abcdfyycxkkczy".match(/(c.)\w+(c.)\w+(f.)?/).to_a # => ["cdfyycxkkczy", "cd", "cz", nil] p "abcdfyycxkkczy".match(/(c.)\w+(c.)\w+(f.)?/).to_s # => "cdfyycxkkczy"
p "abcdfyycxkkczy".match(/(c.)\w+(c.)\w+(f.)?/).to_a # => ["cdfyycxkkczy", "cd", "cz", nil] p "abcdfyycxkkczy".match(/(c.)\w+(c.)\w+(f.)?/).values_at(1, 2) # => ["cd", "cz"]
情報学部 | 菅沼ホーム | 目次 | 索引 |