Today I came across a regex that had to use the
( parenthesis to match a sequence of chars but I wanted just to match them, so I’d love if I could ignore that piece from the “capture” part.
So I learned that we could use
?: in the beginning of the
( and that would turn the capture off for that piece. Check this out;
iex> Regex.scan(~r/aa(bb)(?:cc|CC)/, "aabbccdd aabbCCdd") [["aabbcc", "bb"], ["aabbCC", "bb"]]
In this case I am matching and capturing the
bb sequence and I am matching but not capturing the
cc|CC sequence options.