473,386 Members | 1,801 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,386 software developers and data experts.

change FONT color using Regex.Split

Ada
i'm trying to use Regex to match a 4 number group pattern.
once a match is found, write it to RichTextBox in red.

test data:
This is my 4567 test data.
1234this is another line of data.
Here's two more 9876 5432.
What a headache!!!
result should be the same as the test data above.
except all the 4 group number should be in RED.
it should match the white space, letter case, punctuation, etc.

i tried the SPLIT method in Regex but can't seem to get it to work.
the goal is to get the result to work.
doesn't matter if it's Regex or not.

i think i got confused on how to iterate thru each token (?) and then match
the Regex pattern and do something with it accordingly.

here's what i wanted to achieve.
1) if the Regex pattern is found, write it on screen with RED font.
2) if the Regex pattern doesn't match, write it in black.
3) keep all mechanics, punctuation, etc. as the original text.
appreciate for any inputs.
TIA,
Ada

Nov 16 '05 #1
1 5306
This one seems to work:

string src = @"test data:
This is my 4567 test data.
1234this is another line of data.
Here's two more 9876 5432.
What a headache!!!
";

src.Replace(@"\", @"\\");
src.Replace(@"{", @"\{");
src.Replace(@"}", @"\}");
src = System.Text.RegularExpressions.Regex.Replace
(src, @"((?<=\D|\A)\d{4}(?=\D|\z))", @"{\cf2 $1}");

richTextBox1.Rtf =
@"{\rtf1\ansi{\colortbl;\red0\green0\blue0;\red255 \green0\blue0;}"+src+"}";

However, I didn't have that much time to test it...

Niki

"Ada" <Ad*@discussions.microsoft.com> wrote in
news:3C**********************************@microsof t.com...
i'm trying to use Regex to match a 4 number group pattern.
once a match is found, write it to RichTextBox in red.

test data:
This is my 4567 test data.
1234this is another line of data.
Here's two more 9876 5432.
What a headache!!!
result should be the same as the test data above.
except all the 4 group number should be in RED.
it should match the white space, letter case, punctuation, etc.

i tried the SPLIT method in Regex but can't seem to get it to work.
the goal is to get the result to work.
doesn't matter if it's Regex or not.

i think i got confused on how to iterate thru each token (?) and then match the Regex pattern and do something with it accordingly.

here's what i wanted to achieve.
1) if the Regex pattern is found, write it on screen with RED font.
2) if the Regex pattern doesn't match, write it in black.
3) keep all mechanics, punctuation, etc. as the original text.
appreciate for any inputs.
TIA,
Ada

Nov 16 '05 #2

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

Similar topics

9
by: Ravi Singh (UCSD) | last post by:
Hello all I have a huge string that I need to parse Key <Delim1> Value <Delim2> Key <Delim1> Value <Delim2> Key <Delim1> Value <Delim3> Key <Delim1> Value <Delim2> Key <Delim1> Value...
0
by: Anonieko Ramos | last post by:
Answer. Use IHttpHandler. thanks Ro ry for coming up with this code. It processes css file to add variables. neat idea using System; using System.IO; using System.Text; using...
4
by: Cor | last post by:
Hi Newsgroup, I have given an answer in this newsgroup about a "Replace". There came an answer on that I did not understand, so I have done some tests. I got the idea that someone said,...
3
by: Michael D Murphy | last post by:
Hi, I would like to know how to use Regular Expressions to iteratively return and print the items between the colons in the following string to say the console.. Any help would be appreciated....
7
by: Tim Rogers | last post by:
Hi folks, this is a resolution-detect script that I used on a site. As you can see it is designed to detect when the screen resolution falls below a certain level then load an alternative style...
24
by: garyusenet | last post by:
I'm working on a data file and can't find any common delimmiters in the file to indicate the end of one row of data and the start of the next. Rows are not on individual lines but run accross...
7
by: =?Utf-8?B?amFj?= | last post by:
Hi, I have problems with following code and don’t find the bug : // Set ArrayList aArray = new ArrayList(); regStr = new Regex(@"\?)*(\d+)\]"); if(text != null && regStr.IsMatch(text))...
1
by: neovantage | last post by:
Hey all, I am using a PHP script which creates headings at run time in a sense at page execution. I am stuck a with a very little problem which i am sure i will have the solution from experts. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
0
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...

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.