Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
145 views
in Technique[技术] by (71.8m points)

Regex: match pattern as long as it's not in the beginning

Assume the following strings:

aaa bbb ccc
bbb aaa ccc

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

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

question from:https://stackoverflow.com/questions/15669557/regex-match-pattern-as-long-as-its-not-in-the-beginning

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...