473,387 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

REGEX help

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. :)
Nov 16 '05 #1
2 1964

"John Baro" <jo***@NixSpaMiprimus.com.au.com.au> wrote in message
news:2h************@uni-berlin.de...
===
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.
And it seems that the c not operator (!) works.
ie real(?!ity)
will not match reality
but will match real.

It does not work at the beginning however
ie
(?!ity)real
will match both
real
and
ityreal

Man am I confused

JB :(
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. :)

Nov 16 '05 #2
"John Baro" <jo***@NixSpaMiprimus.com.au.com.au> wrote in
news:2h************@uni-berlin.de:
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.
John,

You can use a negative lookbehind to achieve the match you want:

(?<!\\)\\fcharset\d+

This will match \fcharset1, but not \\fcharset1.

The Regex.Matches method can be used to detect multiple matches in a
regular expression.

bool multipleMatches = Regex.Matches(rtfTextEdit.SelectedRtf,
@"(?<!\\)\\fcharset\d+",
RegexOptions.IgnoreCase |
RegexOptions.IgnorePatternWhitespace |
RegexOptions.Singleline).Count > 1;
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.
The ~(X) construct is specific to the Visual Studio IDE. It does not
work in the .Net framework.
And it seems that the c not operator (!) works.
ie real(?!ity)
will not match reality
but will match real.

It does not work at the beginning however
ie
(?!ity)real
will match both
real
and
ityreal


(?! indicates the beginning of a "zero-width negative lookahead
assertion" construct. A regex like "real(?!ity)" can be read as
"match the characters 'real', if and only if the letters 'ity' do not
appear immediately to the right of the 'l'."
--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search...
20
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
7
by: Mike Labosh | last post by:
I have the following System.Text.RegularExpressions.Regex that is supposed to remove this predefined list of garbage characters from contact names that come in on import files : Dim...
9
by: jmchadha | last post by:
I have got the following html: "something in html ... etc.. city1... etc... <a class="font1" href="city1.html" onclick="etc."click for <b>info</bon city1 </a> ... some html. city1.. can repeat...
4
by: Chris | last post by:
Hi Everyone, I am using a regex to check for a string. When all the file contains is my test string the regex returns a match, but when I embed the test string in the middle of a text file a...
7
by: Extremest | last post by:
I am using this regex. static Regex paranthesis = new Regex("(\\d*/\\d*)", RegexOptions.IgnoreCase); it should find everything between parenthesis that have some numbers onyl then a forward...
6
by: Phil Barber | last post by:
I am using Regex to validate a file name. I have everything I need except I would like the dot(.) in the filename only to appear once. My question is it possible to allow one instance of character...
1
by: jonnyboy6969 | last post by:
Hi All Really hoping someone can help me out here with my deficient regex skills :) I have a function which takes a string of HTML and replaces a term (word or phrase) with a link. The pupose...
0
by: Support Desk | last post by:
That’s it exactly..thx -----Original Message----- From: Reedick, Andrew Sent: Tuesday, June 03, 2008 9:26 AM To: Support Desk Subject: RE: regex help The regex will now skip anything with...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.