0

I'm trying to match contents in the <td> tag inner text of an HTML file using C#.

I'm using the below code to do so:

matchValue = "^.*" + TDInnerText + ".*$";

match = Regex.Match(innerText, @matchValue, RegexOptions.Multiline);
if (match.Success) {
    // Do Something
}

When I debug the program the values under the variables are as follows:

innerText = "\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n Our industry aligned technology architects provide solutions that work and that add exceptional value. We understand business intricacy; we know our technology and we know how to bring this knowledge and understanding together to provide end-to end domain specific intuitive strategic solutions.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"

matchValue = "^.*Our industry aligned technology.*$"

I checked these values in the online regex evaluator and it detected a match. However, the program returns false for match.Success.

Am I missing something here?

Ry-
  • 218,210
  • 55
  • 464
  • 476
Mohit
  • 115
  • 6
  • 1
    It works for me: http://ideone.com/5xuxk – Ry- Nov 26 '11 at 00:42
  • @minitech: When you edited his post you changed his `matchValue` from `matchValue = "^.Our industry aligned technology.$"` to `matchValue = "^.*Our industry aligned technology.*$"` which would match as well, but thus defeats the question/answer. – Aren Nov 26 '11 at 00:42
  • 2
    @Aren: It was because the code was unformatted. The asterisks were there, they were just *making the code italicized*. So `*when I formatted them*` they came back. To see this, use the "source" link on revision #1. – Ry- Nov 26 '11 at 00:43
  • Ah, good call, then my answer is moot, as I read it without the *'s – Aren Nov 26 '11 at 00:44
  • How is innerText defined? As an aside, why are you using '@' before matchValue in the second statement? – user489998 Nov 29 '11 at 17:20
  • You can't parse [X]HTML with Regex: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – Marcel Valdez Orozco Jan 06 '12 at 08:34

0 Answers0