python - Extract an url link "only" with the ".php.com" by regular expression
问题描述
Trying to extract an url link "only" with the ".php.com" (i.e www.sample.php.com) by regular expression, it is not able to extract and identify specific url with (.php.com ) as the following code. Please help and advise me if you got an idea. Thanks in advances.
The following code is able to extract an http or https url , but not able to identify and extract exactly the url only with php.com (i.e www.sample.php.com). How am I supposed to modify the following regular expression to extract the url with ( php.com ) only?
http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*(),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+
<> Only extract url with php.com (www.sample.php.com) , not (www.sample.com or other)
解决方案
You could add a positive lookahead which asserts that one of the URL components is PHP
:
http[s]?://(?=.*\bphp\.com\b)(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*(),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+
^^^ change is here
Demo
推荐阅读
- c++ - C++/Qt 项目的连接函数中不存在插槽?(已经重新制作)
- php - 将网格的内容布局获取到gutenber博客中
- php - 在外部php文件中合并css文件不起作用
- c# - 图像未显示在窗口中,Image.Source 似乎是有效的
- python - 使用 matplotlib 控制 Sankey 图中子系统的位置
- java - Apache Wicket - 自定义 servlet
- user-interface - 为什么图标按钮不居中?
- sql - 使用存储过程的 SQL 注入攻击
- c# - 传递动态方法时出错:不能使用方法组作为参数
- c# - 如何在 C# (Visual Studio) 中进行热键控制