There is a pattern ~//(.+?)//~s , but you need to make sure that it does not catch http://site , that is, it does not work when it comes // before :

How can this be done?

  • ~ are these limiters? Is s a flag? - Mikhail Vaysman

1 answer 1

Use the backward preview block (?<!:) ( find a match if there is no left to the current position : :

 ~(?<!:)//(.+?)//~s 

Demo

PHP has the ability to catch unwanted matches and filter them out using (*SKIP)(*FAIL) :

 ~\b(https?|ftps?)://(*SKIP)(*FAIL)|//(.+?)//~s 

Another demo

Those. find \b(https?|ftps?):// , word boundary, protocols and :// , and then (*SKIP)(*FAIL) delete this match from the buffer, and the next match is searched for from the end of the previous match.