正则表达式:匹配模式,只要它不在开头 [英] Regex: match pattern as long as it's not in the beginning

查看:30
本文介绍了正则表达式:匹配模式,只要它不在开头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有以下字符串:

aaa bbb ccc
bbb aaa ccc

我想匹配 aaa 只要它不在字符串的开头.我试图通过做这样的事情来否定它:

I want to match aaa as long as it is not at the start of the string. I'm trying to negate it by doing something like this:

[^^]aaa

但我认为这是不对的.使用 preg_replace.

But I don't think this is right. Using preg_replace.

推荐答案

您可以查看后面以确保它不在开头.(?

You can use a look behind to make sure it is not at the beginning. (?<!^)aaa

这篇关于正则表达式:匹配模式,只要它不在开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆