You could use a back reference, with this pattern:
(\*{1,2}).+?\1
This means that whatever is captured in the first group (a single or double asterisk) it must be repeated later as \1
.
For example:
NSRegularExpression *regex;
regex = [NSRegularExpression regularExpressionWithPattern:@"(\\*{1,2}).+?\\1"
options:NSRegularExpressionDotMatchesLineSeparators
error:NULL];