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

Categories

I need a Regex to get //, but if it starts with http:// for it to do nothing.

Example:

<?php 
function lol(){
// blabalbal
} // catch'm all

echo 'http://link.com.br'; // this is a link.

Need to catch:

// blabalbal line

// catch'm all line (starting on "// catch")

// this is a link (starting on "// this").

I was trying with variations of: '///(.*)$'

See Question&Answers more detail:os

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

1 Answer

You can use a negative lookbehind which php supports.

(?<!http:)(//.*)

This will only match // if it is not preceded by http:. You may be able to get away with just : depending on your needs.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...