I was trying to find strings out which is followed by only “..”,but couldn’t get that :
["..ab","...cc","..ps","....kkls"].each do |x|
puts x if /../.match(x)
end
..ab
...cc
..ps
....kkls
=> ["..ab", "...cc", "..ps", "....kkls"]
["..ab","...cc","..ps","....kkls"].each do |x|
puts x if /(.)(.)/.match(x)
end
..ab
...cc
..ps
....kkls
=> ["..ab", "...cc", "..ps", "....kkls"]
Expected output:
["..ab","..ps"]
What you want is
The caret
^at the beginning means match the beginning of the string; periods must be escaped by a backslash as\.because in regular expressions a plain period.matches any character; the(?!\.)is a negative look-ahead meaning the next character is not a period. So the expression means, “at the beginning of the string, match two periods, which must be followed by a character which is not a period.”