I need a regex in python that matches any char that is surrounded by exactly 2 underscores.
meaning, meaning
__a__
will match “a”,
but
___a___
will not match.
it needs to support overlapping matches,
such that
__a__d___b___e__c__
will return “ac”
because a is surrounded by double underlines, but d,e have a triple one next to them and b has a triple underline on both sides.
what I have now
(?<=[_]{2})(.)(?=[_]{2})
it solves the overlapping, but not the “exactly 2”
in the above example it returns “adbec”
Try the following:
Examples:
You said you wanted overlapping matches, but if you would not like the
cto match in__a__c__, use the following (which was my original answer):