Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试使用以下代码检查 HTML img 标记中的图像 src
extension.end_with?(/[.jpg|.gif|.png|.jpeg]/).should eq(true)
其中扩展 =“teaser_image610x450.jpg”
我也试过
extension.end_with?(/[.]jpg|gif|png|jpeg/).should eq(true)
在这两种情况下,我都得到了错误。上面的代码有什么问题?
您可以使用以下表格:
extension.end_with?(".jpg",".gif",".png",".jpeg")
或者,像这样:
extensions = [".jpg",".gif",".png",".jpeg"] if extensions.include?(extension) # do something here end
我以前从未见过这种方法与正则表达式一起使用。