Last active
October 28, 2018 01:15
-
-
Save JunichiIto/a06eb6dee923ace3758fa5c5e3e8b2e9 to your computer and use it in GitHub Desktop.
Regex test for ^ and $.
This file contains 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
$ irb | |
irb(main):001:0> "".match? /^/ | |
=> true | |
irb(main):002:0> "".match? /$/ | |
=> true | |
irb(main):003:0> "".match? /^$/ | |
=> true | |
irb(main):017:0> code = <<RUBY | |
irb(main):018:0" [1, 2, 3].each do | |
irb(main):019:0" puts 'Hello, world!' | |
irb(main):020:0" end | |
irb(main):021:0" RUBY | |
=> "[1, 2, 3].each do\n puts 'Hello, world!'\nend\n" | |
irb(main):022:0> | |
irb(main):023:0> # すべての行を# でコメントアウトする | |
=> nil | |
irb(main):024:0> puts code.gsub(/^/, '# ') | |
# [1, 2, 3].each do | |
# puts 'Hello, world!' | |
# end | |
=> nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment