Suppose I have the following text:
__This_is__ a __test__
Using two underscores for denoting italics. So I expect This_is
and test
to be italicized. The logic dictates that any text between two consecutive double underscores should be italicized, including any other number of underscores that may be there. I've got:
__([^_]+)__
What is the equivalent of "not two consecutive underscores" in group 1? Thanks.
An option would be to match two underscores:
Then make a negative look ahead to see if theres no two underscores ahead of the current position:
if that is not the case, match any character:
and repeat the previous one or more times:
and finally match another two underscores:
which is the final solution.
A little demo:
produces:
as can be seen on Ideone.
EDIT
Note that I used a non-capturing group in my demo, otherwise the output would have looked like this:
i.e. the last character matched by
((?!__).)
would have been captured in group 1.More about groups, see: http://www.regular-expressions.info/brackets.html