What is the syntax of this RegEx?

Posted on 2011-04-21
Last Modified: 2013-11-07

  I need to extract the string "I wish to get this" from this string

      <td width="268" style="padding: 2px">I wish to get this</td>

  What is the RegEx to it?
  Marco Castro

[Added Regex zone - mrjoltcola / Zone Advisor]
Question by:MarcoCastro
    1 Comment
    LVL 40

    Accepted Solution

    You should post this in the regex zone.

    For your question, there are several answers. As with most questions of parsing, it depends on how flexible you want to be.

    The simple answer, if all your table rows will look exactly like that you can do:

    <td width="268" style="padding: 2px">(.*)</td>
    // C#
    string pattern = @"<td width=""268"" style=""padding: 2px"">(.*)</td>";

    Open in new window

    But more likely you'll want more flexibility, as that will be too specific.

    <td width=".*?" style=".*?">(.*)</td>
    // C#
    string pattern = @"<td width="".*?"" style="".*?"">(.*)</td>";

    Open in new window

    Or you may not even know that the td tag will have width or style at all, in case maybe something like this one, but your match will be in group 2 ($2)

    // C#
    string pattern = @"<td\s*([^>]*?)>(.*)</td>";

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now