Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.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
Regex 在链接周围添加尖括号_Regex_Sed - Fatal编程技术网

Regex 在链接周围添加尖括号

Regex 在链接周围添加尖括号,regex,sed,Regex,Sed,我想在一行中所有链接的两侧插入。 以下是我的台词 链接以http开头:// 一行有三个字 两个单词之间的空格 每行以两个链接开始,然后是一个字符串或数字 一行可以如下所示: http://website1.com/123123 http://homepage.net/3846 INDONESIA 我尝试了以下方法: sed 's@^http:[^ ]+@<&>@g' sed的@^http:[^]+@@g 但我做错了什么:p 有人可以发布sed声明吗?这条sed一

我想在一行中所有链接的两侧插入<>。 以下是我的台词

  • 链接以http开头://
  • 一行有三个字
  • 两个单词之间的空格
  • 每行以两个链接开始,然后是一个字符串或数字
一行可以如下所示:

http://website1.com/123123  http://homepage.net/3846  INDONESIA
我尝试了以下方法:

sed 's@^http:[^ ]+@<&>@g'
sed的@^http:[^]+@@g
但我做错了什么:p


有人可以发布sed声明吗?

这条sed一行代码在这里工作:

sed 's@\bhttp://\S*@<&>@g'
sed的@\bhttp://\s*@@g
使用您的数据进行测试:

kent$ sed 's@\bhttp://\S*@<&>@g'<<<"http://website1.com/123123  http://homepage.net/3846  INDONESIA"
<http://website1.com/123123>  <http://homepage.net/3846>  INDONESI

kent$sed's@\bhttp://\s*@@g'这个sed一行程序在这里工作:

sed 's@\bhttp://\S*@<&>@g'
sed的@\bhttp://\s*@@g
使用您的数据进行测试:

kent$ sed 's@\bhttp://\S*@<&>@g'<<<"http://website1.com/123123  http://homepage.net/3846  INDONESIA"
<http://website1.com/123123>  <http://homepage.net/3846>  INDONESI

kent$sed's@\bhttp://\s*@@g'您的主要错误是假定“http”位于字符串的开头(使用锚点
^
),但情况并非总是如此。第二个错误是您使用了必须在基本模式下转义的
+
,但您可以使用
*

sed 's@\(^\| \)\(http:[^ ]*\)@\1<\2>@g'
sed的@\(^\\\\)\(http:[^]*\)@\1@g'

您的主要错误是假定“http”位于字符串的开头(使用锚点
^
),但情况并非总是如此。第二个错误是您使用了必须在基本模式下转义的
+
,但您可以使用
*

sed 's@\(^\| \)\(http:[^ ]*\)@\1<\2>@g'
sed的@\(^\\\\)\(http:[^]*\)@\1@g'
sed-r's/http:[^]+//g'
测试:

$echo”http://website1.com/123123  http://homepage.net/3846  印度尼西亚“| sed-r's/http:[^]+//g”
印度尼西亚
sed-r's/http:[^]+//g'
测试:

$echo”http://website1.com/123123  http://homepage.net/3846  印度尼西亚“| sed-r's/http:[^]+//g”
印度尼西亚

我用这个来做大师级的转储:

sed -e "s@\(http://\S\+\)@\<\1\>@g" -e "s@\(^<[^>]*>  <[^>]*>  \)\([^<].*$\|<.\{0,7\}$\|<\([^h]\|h[^t]\|ht[^t]\|htt[^p]\|http[^:]\|http:[^/]\|http:/[^/]\).*$\)@\1\"\"\"\2\"\"\"@g" -e "s@\([^\.]\)[ \t]*\$@\1\.@g"

sed-e“s@”(http://\s\+)@\@g“-e“s@(^]*>]*>\)\([^我将此用于演奏家转储:

sed -e "s@\(http://\S\+\)@\<\1\>@g" -e "s@\(^<[^>]*>  <[^>]*>  \)\([^<].*$\|<.\{0,7\}$\|<\([^h]\|h[^t]\|ht[^t]\|htt[^p]\|http[^:]\|http:[^/]\|http:/[^/]\).*$\)@\1\"\"\"\2\"\"\"@g" -e "s@\([^\.]\)[ \t]*\$@\1\.@g"

sed-e“s@(http://\s++)\@g”-e“s@(^]*>]*>\)([^我看不出有任何理由否决这个问题。我只想指出:检测URL是一个很难解决的问题:呵呵,这是我的第一个方法,但我很快就放弃了。幸运的是,我的URL总是统一的,因此很容易识别。:)我不认为有任何理由对这个问题投反对票。我只是想指出:检测URL是一个很难解决的问题:呵呵,这是我的第一个方法,但我很快就放弃了。幸运的是,我的URL总是统一的,因此很容易识别。:)这很有趣,因为我需要修复virtuoso SPARQL构造查询的输出。我看到您也在行尾添加一个点,然后为文本添加引号。我不知道最后一部分是否在我的数据集中是必需的,但我会使用它。这很有趣,因为我需要修复virtuoso SPARQL构造查询的输出。我看到您也添加了在行尾添加一个点,然后为文字添加引号。我不知道数据集中是否需要最后一部分,但我会使用它。