我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

正则表达式:排除匹配

I have this pattern:

~^([a-z0-9]+[a-z0-9-]+[a-z0-9]+\.([a-z]+)(\.[a-z]+)?)$~i

It will match the following:

xxx.xxx or xxx.xxx.xxx

(number of x per doesn't matter)

How do I disallow xxx.xxx.xxx if the set of characters before the first . is wwww ?

For example, it should allow example.co or example.co.uk but it should not allow www.example.co or www.example.co.uk

You can use a negative lookahead/lookbehind, eg:

~^((?!www\.)[a-z0-9]+[a-z0-9-]+[a-z0-9]+\.([a-z]+)(\.[a-z]+)?)$~i

近期文章

  • session_id不使用session_name
  • MySQL查询优化与统一ID有关
  • cakePHP 1.3:使用Ajax渲染问题
  • 在JS中更改div宽度的百分比
  • 具有多个配置文件PHP MYSQL的计费系统
  • 将表单字段从Coldfusion页面传递给PHP
  • 需要有关谷歌地图嵌入的帮助
  • 在php中使用foreach循环中的where条件
  • Nature Magazine使用什么类型的饲料?
  • MySQL查询输出一小时的值(由timestamp列控制)
  • PHP SQLite搞砸了
  • 在SQLite中没有返回数据时选择随机数据
  • 不带call_user_func_array()传递可变数量的参数
  • php echo变量没有引号
  • MySQL和PHP - 链接实体的逻辑条件分组
  • Doctrine LEFT mysql函数
  • PHP preg_match不匹配
  • pg_query():查询失败:错误:列“x”不存在第2行:SET名称= x
  • joomla-php mysql没有使用先前查询中的数据更新记录
  • Shell脚本以递归方式重命名带有特殊字符的文件名转义?

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华