[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 362
  • Last Modified:

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]
0
MarcoCastro
Asked:
MarcoCastro
1 Solution
 
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

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now