I need to determine when multiple fonts are selected in a richtextbox.
A font is indicated by \fcharset(N) where (N) is a number. (To the best of
my knowledge)
I can use this statement
int Matches = 0;
for(Match m = Regex.Match(rtfTextEdit.SelectedRtf, @"\\fcharset\d");
m.Success; m = m.NextMatch())
{
Matches++;
if(Matches == 2)
{
//multiple fonts selected
break;
}
}
but there has to be an easier way.
I (surely) can specify that I want to match 2 or more \fcharset(n) instances
before a match is set.
This also breaks when I type in \fcharset0 in the textbox which will put
\\\\fcharset0 in the rtf.
Therefore it will match \fcharset0 twice, even though it is the same font.
I therefore need to exclude any instance with \\ in front.
Looking at msdn the ~(X) expression should do this but I cannot get it to
work.
ie ~(\\\\)\\fcharset0
or
~(\\)\\fcharset0
I have downloaded eric gunnersons regex tester from gotdotnet but I cannot
seem to get it to work properly with the above constructs.
It does not seem to recognise the ~(X) construct.
There seem to be major differences between MS regex and say perl regex?
Any help would be muchly appreciated.
Cheers
JB
PS I know I could probably do this with split and replace but I want to
figure out regex. :)