Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.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 - Fatal编程技术网

Regex 如何使用正则表达式获取引号中的内容(不带引号)?

Regex 如何使用正则表达式获取引号中的内容(不带引号)?,regex,Regex,在本例中,所选内容包括引号 "Foo Bar" "Another Value" something else "Suganthan" 正则表达式: (\"[\w\s]+\") 输出: "Foo Bar" "Another Value" "Suganthan" 我只需要打印他们之间的内容。像这样: Foo Bar Another Value Suganthan 如果您不想使用分组,您可以使用积极的前后观: (?<=\")[\w][\w\s]+[\w](?=\") (?如果您不想使用

在本例中,所选内容包括引号

"Foo Bar" "Another Value" something else "Suganthan"
正则表达式:

(\"[\w\s]+\")
输出:

"Foo Bar"
"Another Value"
"Suganthan"
我只需要打印他们之间的内容。像这样:

Foo Bar
Another Value
Suganthan

如果您不想使用分组,您可以使用积极的前后观:

(?<=\")[\w][\w\s]+[\w](?=\")

(?如果您不想使用分组,您可以使用积极的前后观:

(?<=\")[\w][\w\s]+[\w](?=\")

(?首先,匹配带引号的单词(即双引号之间的单词)的更好的正则表达式可能是:

\w+        # Match 1 or more word characters
(?:        # start of a non capturing group
    \s     # match a white-space character
    \w+    # match one more word characters
)*         # 0 or more times
但是要意识到
\w
等同于
[a-zA-z0-9.]
。如果您不想允许使用数字和下划线,请将
\w
替换为
[a-zA-Z]

您没有指定正在使用的语言。如果它支持可变长度look behinds,则可以使用:

(?<=(?:^|\s)")(\w+(?:\s\w+)*)(?=")
将同时识别“ABC”和“DEF”

如果不能使用可变长度的查找断言,则:

(?:(?:^"|\s"))(\w+(?:\s\w+)*)(?=")

首先,匹配引号中的单词(即双引号之间的单词)的更好的正则表达式可能是:

\w+        # Match 1 or more word characters
(?:        # start of a non capturing group
    \s     # match a white-space character
    \w+    # match one more word characters
)*         # 0 or more times
但是要意识到
\w
等同于
[a-zA-z0-9.]
。如果您不想允许使用数字和下划线,请将
\w
替换为
[a-zA-Z]

您没有指定正在使用的语言。如果它支持可变长度look behinds,则可以使用:

(?<=(?:^|\s)")(\w+(?:\s\w+)*)(?=")
将同时识别“ABC”和“DEF”

如果不能使用可变长度的查找断言,则:

(?:(?:^"|\s"))(\w+(?:\s\w+)*)(?=")