开发者

How to use the rails match method with a string?

Is there a way to use the rails match method with a simple string, rather than a regular expression? I'm trying to match a url as such

sometext.match('http://www.example.com')

The problem is, this is stil gettin开发者_如何学Gog evaluated as a regular expression, so I have to escape all the special characters for this to work properly, as such:

sometext.match('http:\/\/www.example\.com\?foo=bar')

If there's no way to match just a string, is there a way to escape it automatically for regular expressions?

Thanks!


If you just want to know if a string is part of another, use include?.

sometext.include?("http://www.example.com/")


You could try something like:

sometext =~ %r{http://example.com?foo=bar}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜