Created
April 2, 2013 00:03
-
-
Save katsuhide/5288850 to your computer and use it in GitHub Desktop.
正規表現を使った文字列の加工
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
a = "foo bar baz" | |
puts a | |
puts a.scan(/f+/) | |
puts "========" | |
b = "foo 10 bar 20 baz 30" | |
puts b | |
puts b.scan(/\w+/) | |
puts "========" | |
arr = ["cat", 123, "#dog", "mouse", "12hoge", "hoge12", "ccat", "hogec"] | |
# pattern = '[A-Za-z].*' | |
pattern = '^c.*' | |
puts arr.grep(/#{pattern}/) | |
puts "========" | |
body = ['<td colspan="1" rowspan="1" style="padding: 10px; border-bottom: solid 1px #ddd;">2013/02/13 21:27</td></tr>', 'hoge'] | |
pattern = '<.*?>' | |
temp = body.reject{ |e| e =~ /#{pattern}/} | |
puts temp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment