0

Regex is not being very friendly with me, giving me 0 matches haha.

Basically, I have a big string, that includes this:

                            <td class="fieldLabel02Std">FIELD_LABEL</td>
                            <td class="fieldLabel02Std">


                                    VALUE

                            </td>

Thanks to the FIELD_LABEL I should be able to find it inside the bigger string. The "VALUE" is what I want to get.

I tried this pattern

String field = "FIELD_NAME";
String pattern = field + @"[\s\S]*?\<td[\s\S]*?\<\/td\>";

That didn't work. I was thinking about this: Get the field_name + some characters + => which would be able to give me VALUE.

This gives me 0 matches.

Help is very appreciated!

Kevin Van Ryckegem
  • 1,915
  • 3
  • 28
  • 55
  • I am ethically required to inform you that in general, if you are parsing an HTML page, it would probably be easier to just use an HTML parser than to attempt to craft a regular expression that does the same thing. – murgatroid99 Nov 11 '13 at 19:07
  • [You can't parse HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to correctly parse HTML...](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/) – jbabey Nov 11 '13 at 19:08
  • Well it does say "it's sometimes appropriate to parse a limited, known set of HTML." => I think it's pretty limited here. If I get this pattern right, everything would be working. – Kevin Van Ryckegem Nov 11 '13 at 19:11

3 Answers3

0

You can use something like this:

FIELD_LABEL</td>[\n\r\s]*<td class="fieldLabel02Std">[\n\r\s]*(.+?)[\n\r\s]*</td>

Generally it's bad to use a regex to parse HTML, but if you have a small problem with a known html format and you don't mind if this stop working when they change a comma...

Guilherme Bernal
  • 8,183
  • 25
  • 43
0

Consider the following Regex...

(?<=FIELD_LABEL[\S\s]*?\<td.*?\>[\S\s]*?)\w+(?=[\S\s]*?\</td\>)

Good Luck!

gpmurthy
  • 2,397
  • 19
  • 21
0

Is this what You looking for?

FIELD_LABEL<\/td>[.\s]*?<td.*?>[.\s]*?VALUE[.\s]*?<\/td>

or

String pattern = field + @"<\/td>[.\s]*?<td.*?>[.\s]*?VALUE[.\s]*?<\/td>";

Kamil Wozniak
  • 430
  • 3
  • 7