Pregunta

cómo consigo la expresión regular mencionó en este artículo trabajar con preg_match en php?

<?php
preg_match("\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))/i", $text, $matches);
print_r($matches);
?>

Usando el código anterior me sale el siguiente error:

Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash...
¿Fue útil?

Solución

Prueba esto:

preg_match("#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#i", $text, $matches);

faltaban los delimitadores de expresiones regulares (por lo general /, pero utilizando # aquí porque es más conveniente para las direcciones URL)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top