473,671 Members | 2,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(rtf TextEdit.Select edRtf, @"\\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 ~(\\\\)\\fchars et0
or
~(\\)\\fcharset 0

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 1995

"John Baro" <jo***@NixSpaMi primus.com.au.c om.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 ~(\\\\)\\fchars et0
or
~(\\)\\fcharset 0

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***@NixSpaMi primus.com.au.c om.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(rtf TextEdit.Select edRtf,
@"\\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:

(?<!\\)\\fchars et\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(r tfTextEdit.Sele ctedRtf,
@"(?<!\\)\\fcha rset\d+",
RegexOptions.Ig noreCase |
RegexOptions.Ig norePatternWhit espace |
RegexOptions.Si ngleline).Count > 1;
Looking at msdn the ~(X) expression should do this but I
cannot get it to work.
ie ~(\\\\)\\fchars et0
or
~(\\)\\fcharset 0

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
4789
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 string. It's actually the input string into a Microsoft Index Server search. The string will consist of words, perhaps enclosed in quotes or parentheses. I'd like to use Regex to pull out the words, or the phrases if the words are enclosed in quotes....
20
8093
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 matches are called within a loop (like if or for). E.g. for(int i = 0; i < 10; i++) { Regex r = new Regex();
17
3961
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 http://forta.com/books/0672325667/
7
2226
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 _dropContactGarbage As New Regex( _ "(+)|" & _ "(+)|" & _ "(+)|" & _ "(+)|" & _ "(+)|" & _
9
2081
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 lot of times here.... Requirement: ------------------- I want to get the value of "href" i.e "city1.html" by searching "city1" between the <a</atag. Please note that "city1" can repeat lot of
4
2635
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 match is never returned. The string that I give to the regex is one that contains the entire contents of a text file. I'm using the multi-line option and I've also tried stripping out the VbCr
7
2580
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 slash then some numbers. For some reason I am not getting that. It won't work at all in 2.0
6
4204
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 but not two or more? example myfile.doc = good My.file.doc = not good if you could give an example of the expression pattern that would most helpful. thanks phil
1
12178
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 is that I seek out terms which are in a glossary on our site, and automatically link to this definition. Its slightly complex becase certain elements have to be ignored, for exampleI dont want to add links within existing links, or for example link...
0
1622
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 an '@'in the filename on the assumption it's already in the correct format. Uncomment the os.rename line
0
8476
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8393
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8821
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8670
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4407
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2812
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1809
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.