开发者

php regular expression assistance bold a filename

开发者 https://www.devze.com 2022-12-25 05:17 出处:网络
I am not very good, with regular expression开发者_如何学JAVA in php I am trying to get a reg_expression to find all file names such as /file-name-here.php and make it bold.

I am not very good, with regular expression开发者_如何学JAVA in php I am trying to get a reg_expression to find all file names such as /file-name-here.php and make it bold.

This expression works in Flash but not in php it also doesn't accept the '-' i'm not sure why i can't get it to work with preg_replace

/(https?://)?(www\.)?([a-zA-Z0-9_%]*)\b\.[a-z]{2,4}(\.[a-z]{2})?((/[a-zA-Z0-9_%]*)+)?(\.[a-z]*)?/g


I think you need to escape your forward slashes:

/(https?:\/\/)?(www\.)?([a-zA-Z0-9_%]*)\b\.[a-z]{2,4}(\.[a-z]{2})?((\/[a-zA-Z0-9_%]*)+)?(\.[a-z]*)?/g

Or you could use a different delimiter (in PHP, the first character is the delimiter for the regular expression):

@(https?://)?(www\.)?([a-zA-Z0-9_%]*)\b\.[a-z]{2,4}(\.[a-z]{2})?((/[a-zA-Z0-9_%]*)+)?(\.[a-z]*)?@g
0

精彩评论

暂无评论...
验证码 换一张
取 消