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

Regular Expressions help

So basically I made a kind of html editor, where u can type ur html code... now I want to make code inside < > blue (including the <, >) I already made it ignore stuff like <> and < (how many spaces, doesnt matter) > becuase it basically does print those stuff to web (thats how html works)

Now it works great and all, but when I do something like this:

<br
>

It doesnt make that text blue... this is my code:
Expand|Select|Wrap|Line Numbers
  1.         private void richTextBox1_TextChanged(object sender, EventArgs e)
  2.         {
  3.             int selectionStart = this.richTextBox1.SelectionStart;
  4.             Regex regexObj = new Regex(this.richTextBox1.Text, RegexOptions.Singleline);
  5.             Match matchObj = Regex.Match(this.richTextBox1.Text, "<.*?>");
  6.             while (matchObj.Groups.SyncRoot.ToString() != "")
  7.             {
  8.                 string str = matchObj.Groups.SyncRoot.ToString();
  9.                 if(str != "<>")
  10.                 {
  11.                     int pass = 0;
  12.                     for (int i = 1; i < str.Length - 1; i++)
  13.                     {
  14.                         if (str[i].ToString() != " ")
  15.                         {
  16.                             pass = 1;
  17.                         }
  18.                     }
  19.                     if (pass == 1)
  20.                     {
  21.                         this.richTextBox1.SelectionStart = matchObj.Index;
  22.                         this.richTextBox1.SelectionLength = matchObj.Length;
  23.                         if (this.richTextBox1.SelectionColor != Color.Blue)
  24.                         {
  25.                             this.richTextBox1.SelectionColor = Color.Blue;
  26.                         }
  27.                     }
  28.                 }
  29.                 matchObj = matchObj.NextMatch();
  30.             }
  31.             this.richTextBox1.SelectionStart = selectionStart;
  32.             this.richTextBox1.SelectionLength = 0;
  33.             this.richTextBox1.SelectionColor = Color.Black;
  34.         }
  35.  
Jan 2 '07 #1
2 1100
kenobewan
4,871 Expert 4TB
What happens if you comment out the last three lines and uncomment them one at a time?

Expand|Select|Wrap|Line Numbers
  1. /*this.richTextBox1.SelectionStart = selectionStart;
  2.             *this.richTextBox1.SelectionLength = 0;
  3.             *this.richTextBox1.SelectionColor = Color.Black;*/
Jan 2 '07 #2
I made it so if ur in the middle on the richTextBox so it comes back to that location after it colors what is needed to be colored... u wont all of a sudden start from the end of the richTextbox writing.
Jan 3 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Martin Robins | last post by:
I am trying to parse a string that is similar in form to an OLEDB connection string using regular expressions; in principle it is working, but certain character combinations in the string being...
4
by: GenoJoe | last post by:
If you are not new to VB.NET but are new to regular expressions, you need to get a free copy of "Pragmatic Guide to Regular Expressions for VB.NET Programmers". I wrote this guide because all of the...
2
by: cleo | last post by:
I'm experimenting with Regular Expressions and Windows Forms. Frequently I want a value to be either a valid pattern or empty. For example a Zip code must be 5 digits or may be empty. I know that...
7
by: norton | last post by:
Hello, Does any one know how to extact the following text into 4 different groups(namely Date, Artist, Album and Quality)? - Artist - Album Artist - Album - Artist - Album - Artist -...
4
by: lucky | last post by:
hi there!! i'm looking for a code snipett wich help me to search some words into a particular string and replace with a perticular word. i got a huge data string in which searching traditional...
4
by: Együd Csaba | last post by:
Hi All, I'd like to "compress" the following two filter expressions into one - assuming that it makes sense regarding query execution performance. .... where (adate LIKE "2004.01.10 __:30" or...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
3
by: a | last post by:
I'm a newbie needing to use some Regular Expressions in PHP. Can I safely use the results of my tests using 'The Regex Coach' (http://www.weitz.de/regex-coach/index.html) Are the Regular...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
3
by: Zeba | last post by:
Hi guys, I need some help regarding regular expressions. Consider the following statement : System.Text.RegularExpressions.Match match =...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.