[英].NET Regex match space character when IgnorePatternWhitespace is on
我有一個很大的正則表達式,我已經打開了IgnorePatternWhitespace,所以我可以讓它更具可讀性。 我的問題是我想匹配一個文字空格字符。 最好的方法是什么?
一個例子:
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);
在上面的例子中,“我的短語”應該包含一個空格。
使用“\\ s”或“[]”
看起來您可以使用反斜杠簡單地轉義空格字符:
My\ phrase
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.