I want to see if a certain pattern is inside an array. I tried:
myArray.flatten.include?(/myPattern/)
but it always return false. Why? Is it because the "include?" doesn't takes
regular expressions?
Here's another example that I tried inside an irb session:
I'd go for any? as it short circuits, i.e. terminates after the first successful match.
Kind regards
robert
···
Boucher, Eric <eric.boucher@messier-dowty.com> wrote:
Hi,
I want to see if a certain pattern is inside an array. I tried:
myArray.flatten.include?(/myPattern/)
but it always return false. Why? Is it because the "include?" doesn't
takes regular expressions?
Here's another example that I tried inside an irb session:
I want to see if a certain pattern is inside an array. I tried:
myArray.flatten.include?(/myPattern/)
but it always return false. Why? Is it because the "include?" doesn't takes
regular expressions?
Here's another example that I tried inside an irb session:
I want to see if a certain pattern is inside an array. I tried:
myArray.flatten.include?(/myPattern/)
but it always return false. Why? Is it because the "include?" doesn't takes
regular expressions?
Here's another example that I tried inside an irb session:
What about using:
data.match(/TC_TP/)
should return nil if it doesn't match, otherwise returns the matching
string.
It doesn't return the matching string but an object of type MatchData. The matched string can be extracted from that. Another form is to use String# with regexp, like