Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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_Match - Fatal编程技术网

Regex 正则表达式匹配问题

Regex 正则表达式匹配问题,regex,match,Regex,Match,如果我有一个字符串,比如 很多人都在说“一些重要的”或者其他的东西 是否有可能让正则表达式只匹配“”之间的任何内容,而不包括引号?因此,检测它的方法类似于“*”,但如果您的正则表达式引擎支持零宽度断言(向后看,向前看),那么它将返回“somethingingportant”,而不仅仅是纯somethingportant 匹配所有内容,包括引号,然后将组1(括号集)从匹配中拉出。如果您的正则表达式引擎支持零宽度断言(look behinds和look aheads) "(.*)" 匹配所有内容,

如果我有一个字符串,比如

很多人都在说“一些重要的”或者其他的东西


是否有可能让正则表达式只匹配“”之间的任何内容,而不包括引号?因此,检测它的方法类似于“*”,但如果您的正则表达式引擎支持零宽度断言(向后看,向前看),那么它将返回“somethingingportant”,而不仅仅是纯somethingportant


匹配所有内容,包括引号,然后将组1(括号集)从匹配中拉出。

如果您的正则表达式引擎支持零宽度断言(look behinds和look aheads)

"(.*)"
匹配所有内容,包括引号,然后将组1(括号集)从匹配中拉出

"(.*)"
可以使用括号创建捕获组。访问它的方式取决于所使用的语言/库——通常捕获组在类似Perl的语言中以
$1
\1
的形式提供。例如,在Perl中:

'hello "world" !!!' =~ /"(.*)"/;
print "$1\n";
可以使用括号创建捕获组。访问它的方式取决于所使用的语言/库——通常捕获组在类似Perl的语言中以
$1
\1
的形式提供。例如,在Perl中:

'hello "world" !!!' =~ /"(.*)"/;
print "$1\n";
请尝试
“(.*?”

表示在本例中,
*
将根据需要展开(直到与下一个匹配)

Java代码:

static String regex = "\"(.*?)\"";
static Pattern p = Pattern.compile(regex);

public static List<String> getMatches(String inputText) {
    Matcher m = p.matcher(inputText);
    List<String> list = new ArrayList<String>();
    while(m.find()){
        list.add(m.group(1));
    }
    return list;
}
静态字符串regex=“\”(.*)\”;
静态模式p=Pattern.compile(regex);
公共静态列表getMatches(字符串输入文本){
匹配器m=p.Matcher(输入文本);
列表=新的ArrayList();
while(m.find()){
列表。添加(m.组(1));
}
退货清单;
}
试试
“(.*)”

表示在本例中,
*
将根据需要展开(直到与下一个匹配)

Java代码:

static String regex = "\"(.*?)\"";
static Pattern p = Pattern.compile(regex);

public static List<String> getMatches(String inputText) {
    Matcher m = p.matcher(inputText);
    List<String> list = new ArrayList<String>();
    while(m.find()){
        list.add(m.group(1));
    }
    return list;
}
静态字符串regex=“\”(.*)\”;
静态模式p=Pattern.compile(regex);
公共静态列表getMatches(字符串输入文本){
匹配器m=p.Matcher(输入文本);
列表=新的ArrayList();
while(m.find()){
列表。添加(m.组(1));
}
退货清单;
}

实际上,它并不能完全解决问题,因为组中没有括号。谢谢,这就是我要找的。实际上,它并不能完全解决问题,因为组中没有括号。谢谢,这就是我要找的。