[英]C# Regex to match Url folder pattern
I have an application which needs to find and then process Urls which follow a pattern like this: http://www.actuino.fr/projets/frankenblink http://www.actuino.fr/projets/ http://www.actuino.fr/projets
我有一个应用程序,需要找到并处理Urls遵循这样的模式:
http://www.actuino.fr/projets/frankenblink http://www.actuino.fr/projets/ http://www.actuino.fr/projets
//www.actuino.fr/projets/frankenblink http://www.actuino.fr/projets/frankenblink http://www.actuino.fr/projets/ http://www.actuino.fr/projets
I have the following pattern which almost works... 我有以下几乎可以工作的模式......
string pattern = @"http://www.actuino.fr/projets/?.*";
Unfortunately that pattern will grab all Urls with 'projets' in as like this 不幸的是,这种模式将使用'projets'来抓取所有Urls
http://www.actuino.fr/projetsarduino http://www.actuino.fr/projets_rasberry
Thank you for your time. 感谢您的时间。
Use word boundary. 使用单词边界。
string pattern = @"http://www\.actuino\.fr/projets\b/?.*";
or 要么
Positive lookahead Assertion. 积极的前瞻断言。
string pattern = @"(?m)http://www\.actuino\.fr/projets(?=/|$)/?.*";
(?=/|$)
asserts that the previous token projects
must be followed by a /
or end of the line. (?=/|$)
断言先前的令牌projects
必须后跟一行/
或一行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.