SingingEels : Development Community & Resource

Login

Articles

  • ADO.NET (2)
  • ASP.NET (36)
  • LINQ (4)
  • Security (2)
  • Silverlight (3)
  • SQL (7)
  • Standards (5)
  • WCF (2)

Syndication

  • Articles RSS
  • Blogs RSS

Contribute

  • Our Authors List
  • Member Sign-Up
  • Suggestions Box
ASP.NET Hosting with MS SQL 2008 – Click Here!

Sweet Regex - "While Not Between"

(Aug 17 2007 - 01:16:51 PM by Timothy Khouri) - [print blog post]

I love when a complex problem is solved with a regular expression... and I probably would not have had any other way to accomplish this need without coming up with a nice regex I call "While Not Between".

Basically, the scenario was this: While writing an article on Eels, I wanted to include an HTML sample containing an "un-ordered list". This is simple enough, but the problem was that the Eels article engine was turning this:

<ul>
   <li>Test</li>
</ul>

Into this:

  • Test

So, after debugging for a few hours and stepping through the article engine's formatting code, I realized that I didn't want to parse a "<ul>" tag while it was between "[code][/code]" blocks. So, I came up with this one regex to rule them all:

(?<!aaa((?!bbb)[\s\S])*)SomeText

This will match the word "SomeText" in this sentense, but it won't match "aaaSomeTextbbb". I've explained it a little better on RegexLib.com.

You must be logged in to add comments. If you have not already done so, you can create an account here. If you already are a member, you first need to login before you can comment.

Developer / Architect / Author

Blog Archives

  • November 2008 - (1)
  • October 2008 - (2)
  • September 2008 - (2)
  • August 2008 - (3)
  • July 2008 - (1)
  • June 2008 - (3)
  • May 2008 - (2)
  • April 2008 - (2)
  • March 2008 - (4)
  • February 2008 - (2)
  • December 2007 - (2)
  • November 2007 - (1)
  • October 2007 - (4)
  • September 2007 - (9)
  • August 2007 - (7)

Related Ads

SingingEels.com as of Jan 05 2009 - 07:18:06 PM - (0.0624984)