Easy regular expression
This pertains to a regex expression.If I have a docu开发者_StackOverflow中文版ment with the word Chapter in it how could I select the space right before it?
\s+(?=Chapter)
should do it. \s+
matches space, and (?=Chapter)
matches the zero-length string that is followed by the word "Chapter".
For .net, space is defined in http://msdn.microsoft.com/en-us/library/ms972966.aspx thus:
\s
Matches any white-space character. Equivalent to the Unicode character classes[\f\n\r\t\v\x85\p{Z}]
. If ECMAScript-compliant behavior is specified with the ECMAScript option,\s
is equivalent to[ \f\n\r\t\v]
(note leading space).
精彩评论