What is the syntax of this RegEx?

Hi,

  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?
  Thanks,
  Marco Castro

[Added Regex zone - mrjoltcola / Zone Advisor]
MarcoCastroAsked:
Who is Participating?
 
mrjoltcolaCommented:
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)

<td\s*([^>]*?)>(.*)</td>

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

Open in new window


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.