Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
NSRegularExpression+;iOS+;HTML中的URL_Ios_Regex - Fatal编程技术网

NSRegularExpression+;iOS+;HTML中的URL

NSRegularExpression+;iOS+;HTML中的URL,ios,regex,Ios,Regex,可能重复: 我有这样一个字符串: NSString *string = @"<a href='http://john.com'>JOHN</a> http://john.com"; 这会检测URL,但也会检测锚标记中的URL,这是有问题的 有人知道我需要做什么吗? 谢谢 更新: @"([^\'](https?):\\/\\/[-A-Z0-9+&@#\\/%?=~_|!:,.;]*[-A-Z0-9+&@#\\/%=~_|][^\'])" 下面Alex提

可能重复:

我有这样一个字符串:

NSString *string = @"<a href='http://john.com'>JOHN</a> http://john.com";
这会检测URL,但也会检测锚标记中的URL,这是有问题的

有人知道我需要做什么吗? 谢谢

更新:

@"([^\'](https?):\\/\\/[-A-Z0-9+&@#\\/%?=~_|!:,.;]*[-A-Z0-9+&@#\\/%=~_|][^\'])"

下面Alex提供的这种模式是一种改进。但如果我有这样的字符串@“john.com”——example.com是匹配的。我怎么能排除这一点?基本上,我不希望锚定标记中的任何内容被匹配。

一般来说,考虑到正则表达式的工作原理,尝试捕获“非”某物要比尝试捕获某物困难得多。您可以通过一些sed命令或strip等的实现轻松实现上述功能

考虑到您上面的格式,您是喜欢这项工作,还是打算为您排除太多的角落案例

"([^\'](https?):\\/\\/[-A-Z0-9+&@#\\/%?=~_|!:,.;]*[-A-Z0-9+&@#\\/%=~_|][^\'])"
例如,我们希望确保您的URL不在引号内。它会在以下方面失败:

"tom went to 'https://www.google.com' to find the..."

但我不知道这对你是否重要。

这很有效。但是如果我有一个像这样的字符串@“”;-是匹配的。我怎么能排除这一点?基本上,我不希望锚标签中的任何内容匹配。
"tom went to 'https://www.google.com' to find the..."