Created
August 3, 2010 01:14
-
-
Save huacnlee/505648 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
# Ruby 正则匹配查找替换例子 | |
body = "这里是内容<img src='uploads/a.jpg' />asdgasdgasdg<img src=\"uploads/b.jpg\" alt=\"\">这里是内容是哪的客观加拉塞克的构建" | |
regex = Regex.new("<(img.+?src\\=[\"|']{0,1})(.+?)>",[Regexp::EXTENDED,Regexp::IGNORECASE]) | |
# 用 String.scan 搜索匹配字符串中的多个 img 标签 | |
body.scan(regex).each do |m| | |
puts "matched: #{m.to_s}" | |
# m[0] 是正则里面的第一个()匹配项 | |
puts m[0] | |
puts m[1] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment