Skip to content

Instantly share code, notes, and snippets.

@JunichiIto
Last active October 28, 2018 01:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JunichiIto/a06eb6dee923ace3758fa5c5e3e8b2e9 to your computer and use it in GitHub Desktop.
Save JunichiIto/a06eb6dee923ace3758fa5c5e3e8b2e9 to your computer and use it in GitHub Desktop.
Regex test for ^ and $.
$ 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