Created
January 6, 2016 18:19
-
-
Save hackugyo/529ea8dc64e2403b92fd to your computer and use it in GitHub Desktop.
与えられたカッコ(なんでも.開きと閉じとの定義を引数にくれればいい)内を抜き出します. ruby extract_between_parentheses.rb "「」" YOUR_FILE_NAME
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| open_paren = Regexp.quote(ARGV[0][0]) | |
| close_paren = Regexp.quote(ARGV[0][1]) | |
| open(ARGV[1]).read.lines | |
| .select {|x| x.include?(ARGV[0][0]) && x.include?(ARGV[0][1])} | |
| .map{|x| | |
| x | |
| .gsub(/^(.*?)#{open_paren}/, "#{open_paren}") | |
| .gsub(/#{close_paren}[^#{open_paren}]*$/, "#{close_paren}") | |
| .gsub(/#{close_paren}.*?#{open_paren}/,"#{close_paren}#{open_paren}") | |
| }.join('').split(ARGV[0][1]).each{|x| puts "#{x + ARGV[0][1]}"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment