How to use the method of matching rails with a string?

Is there a way to use the rails method matchwith a simple string and not with a regular expression? I am trying to map url as such

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

The problem is that this evaluates to a regular expression, so I need to avoid all special characters to work correctly:

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

If there is no way to match only strings, is there a way to automatically avoid it for regular expressions?

Thank!

+3
source share
2 answers

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

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

- :

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

Source: https://habr.com/ru/post/1762552/


All Articles