Results 1 to 2 of 2

Thread: [2.0] Regular Expressions and BB Code

  1. #1

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Question [2.0] Regular Expressions and BB Code

    So I'm working on a very rudimentary BB Code parsing component that will be used by a handful of people. I'm very bad at regular expressions but I was able to piece several together from internet examples as well as direct copy and paste from other places. They don't seem to consistently work. So my questions are thus:
    1. Can these regular expressions be improved and if so how? Are they fundamentally broken or missing pieces?
    2. What's a good resource where folks can learn about regular expressions from the ground up and then utilizing them in C#?


    The following is a set of static properties that have defined regular expressions in them for parsing [P], [I], [B], [STRIKE], [CODE], [IMG] (includes ALT text and works like [URL]), [QUOTE], and [URL].
    Code:
    public static Regex P { get { return new Regex(@"\[p\](.+?)\[\/p\]", RegexOptions.IgnoreCase); } }
    public static Regex I { get { return new Regex(@"\[i\](.+?)\[\/i\]", RegexOptions.IgnoreCase); } }
    public static Regex U { get { return new Regex(@"\[u\](.+?)\[\/u\]", RegexOptions.IgnoreCase); } }
    public static Regex B { get { return new Regex(@"\[b\](.+?)\[\/b\]", RegexOptions.IgnoreCase); } }
    public static Regex Strike { get { return new Regex(@"\[strike\](.+?)\[\/strike\]", RegexOptions.IgnoreCase); } }
    public static Regex Code { get { return new Regex(@"\[code\](.+?)\[\/code\]", RegexOptions.IgnoreCase); } }
    public static Regex Image { get { return new Regex(@"\[img=([^\]]+)\]([^\]]+)\[\/img\]", RegexOptions.IgnoreCase); } }
    public static Regex Quote { get { return new Regex(@"\[quote=([^\]]+)\]([^\]]+)\[\/quote\]", RegexOptions.IgnoreCase); } }
    public static Regex Url { get { return new Regex(@"\[url=([^\]]+)\]([^\]]+)\[\/url\]", RegexOptions.IgnoreCas
    e); } }
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  2. #2
    Addicted Member
    Join Date
    Jan 2007
    Posts
    162

    Re: [2.0] Regular Expressions and BB Code

    I just finished building a webcrawler together with my groupmate. While working on this project, i saw several groups used something called a RegEx builder, which helped them build the RegEx used to parse out certain element of a given content. You could try and have a look at this: http://www.regexbuddy.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width