php - Regex, ignore results with preceding character -



php - Regex, ignore results with preceding character -

i have regex matching urls ((https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\s*)?) , job, works want. match domain e-mail when don't want to.

currently matchs:

http://www.foo.bar foo.bar website: foo.bar (matches foo.bar part) info@foo.bar (matches foo.bar part)

i don't want match lastly one, matches first three. tried adding (?!=@) front end didn't it. how can ignore results preceded @ symbol?

add anchors regex

^((https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\s*)?)$

see illustration http://regex101.com/r/li8kz6/1

explantion

^ asserts regex @ start of line

$ asserts regex @ end of line

edit

if urls embedded within text utilize \s delemit regex match strings as

(\s|^)((https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\s*)?)\s

see example

http://regex101.com/r/li8kz6/3

php regex

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -