我有以下字符串:
"Look on http://www.google.com".
Run Code Online (Sandbox Code Playgroud)
我需要将其转换为:
原始字符串可以包含多个URL字符串.
我怎么在PHP中这样做?
谢谢
如何设置我的正则表达式进行测试,以查看URL是否包含在javascript中的文本块中.我无法弄清楚用来完成这个的模式
var urlpattern = new RegExp( "(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?"
var txtfield = $('#msg').val() /*this is a textarea*/
if ( urlpattern.test(txtfield) ){
//do something about it
}
Run Code Online (Sandbox Code Playgroud)
编辑:
所以我现在使用的模式在正则表达式测试器中用于我需要它做什么,但是chrome会抛出一个错误
"Invalid regular expression: /(http|ftp|https)://[w-_]+(.[w-_]+)+([w-.,@?^=%&:/~+#]*[w-@?^=%&/~+#])?/: Range out of order in character class"
Run Code Online (Sandbox Code Playgroud)
对于以下代码:
var urlexp = new RegExp( '(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?' );
Run Code Online (Sandbox Code Playgroud)