嗨,假设您有以下来自' some_command':
的输出DEPENDENCY archy@0.0.2
DEPENDENCY bower-config@~0.5.2
DEPENDENCY bower-endpoint-parser@~0.2.2
DEPENDENCY bower-json@~0.4.0
DEPENDENCY bower-logger@~0.2.2
DEPENDENCY bower-registry-client@~0.2.0
DEPENDENCY cardinal@0.4.0
DEPENDENCY chalk@0.5.0
DEPENDENCY chmodr@0.1.0
DEPENDENCY decompress-zip@0.0.8
DEPENDENCY fstream@~1.0.2
DEPENDENCY fstream-ignore@~1.0.1
DEPENDENCY glob@~4.0.2
DEPENDENCY graceful-fs@~3.0.1
DEPENDENCY handlebars@~2.0.0
DEPENDENCY inquirer@0.7.1
DEPENDENCY insight@0.4.3
DEPENDENCY is-root@~1.0.0
DEPENDENCY junk@~1.0.0
DEPENDENCY lockfile@~1.0.0
DEPENDENCY lru-cache@~2.5.0
DEPENDENCY mkdirp@0.5.0
DEPENDENCY mkdirp@^0.5.0
DEPENDENCY chalk@^0.5.0
DEPENDENCY graceful-fs@~3.0.1
DEPENDENCY mkdirp@~0.5.0
DEPENDENCY mkdirp@^0.5.0
我想要做的是获取图书馆名称,包括没有' DEPENDENCY'部分。我正在使用:
> some_command | grep -ioE '(?:dependency )(.+)'
非捕获组应该忽略了依赖性'部分,但它不是。
我做错了什么? (我在Mac OS X Yosemite上)
如果有人可能从解决类似的Mac OS X grep问题中获益,可以选择以下链接:http://www.heystephenwood.com/2013/09/install-gnu-grep-on-mac-osx.html
答案 0 :(得分:3)
grep
中没有非捕获组。您可以做的是使用Perl regexp中{{1}}的后视:
-P
使用您的输入对文件执行它,它返回:
grep -Pio '(?<=dependency )(.+)'
由于您没有archy@0.0.2
bower-config@~0.5.2
bower-endpoint-parser@~0.2.2
bower-json@~0.4.0
bower-logger@~0.2.2
...
,您可以使用其他任何一种方法(其中包括!):
-P
如果一行以此字符串开头,它们总是打印sed '/^DEPENDENCY/s/^DEPENDENCY //'
awk '/^DEPENDENCY/ {print $2}'
之后的内容。
答案 1 :(得分:1)
非捕捉部分不会忽略匹配,我只是将其从匹配组中排除..您可以使用@Path("/hello")
public class Hello {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello GET String";
}
@POST
@Produces(MediaType.TEXT_PLAIN)
public String post(@QueryParam("param1")String param1, @QueryParam("param2")String param2){
String msg = param1+param2;
return msg;
}
/*
public Response post(@QueryParam("param1")String param1, @QueryParam("param2")String param2){
String msg = param1+param2;
return Response.ok(msg).build();
}
public Response post(@QueryParam("param1")String param1, @QueryParam("param2")String param2){
String msg = param1+param2;
return Response.ok().build();
}
public Response post(@Context UriInfo ui){
MultivaluedMap<String, String> queryParams =ui.getQueryParameters();
String msg = param1+param2;
Response r = null;
return r;
}
*/
}
切换后面的后面看...
P