我有这个正则表达式:
Regex BodyEndTagRegex = new Regex("</body>(.*)$",RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Multiline);
注意我是如何用$来寻找字符串的结尾.
是否对.NET的正则表达式进行了优化,以便它不必扫描整个字符串?如果没有,我怎样才能优化它到最后开始?
我相信关键点是:
By default,the regular expression engine searches from left to right.
You can reverse the search direction by using the
RegexOptions.RightToLeft option. The search automatically begins at
the last character position of the string. For pattern-matching
methods that include a starting position parameter,such as
Regex.Match(String,Int32),the starting position is the index of the
rightmost character position at which the search is to begin.
重要:
The RegexOptions.RightToLeft option changes the search direction only; it does not interpret the regular expression pattern from right to left
原文地址:https://www.jb51.cc/regex/356615.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。