Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Regex match space character when IgnorePatternWhitespace is on

Tags:

.net

regex

I have a large regular expression and I've turned on IgnorePatternWhitespace so I can make it more readable. My problem is that I want to match a literal space character. What's the best way to do that?

An example:

Regex myRegex = new Regex(@"
  (?> <table[^>]*> ) # Find a table
  (?> .*?<tr> ) # Find the first row
  (?> .*?<th> ) # Find the first header column
  My phrase # Look for our key phrase
  etc.
", RegexOptions.IgnorePatternWhitespace);

In the above example, "My phrase" should include a space.

like image 888
Jeremy Stein Avatar asked Jun 10 '09 18:06

Jeremy Stein


1 Answers

Use "\s" or "[ ]"

like image 86
Jeff Moser Avatar answered Sep 28 '22 11:09

Jeff Moser