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
Regex/grep将点路径从字符串中拉出_Regex_Grep - Fatal编程技术网

Regex/grep将点路径从字符串中拉出

Regex/grep将点路径从字符串中拉出,regex,grep,Regex,Grep,下面的字符串可能会在不同的文档中以不同的格式出现任意次数,我想把引号之间的部分去掉。我只想要满足以下条件的字符串。以“(两个引号之间)开头和结尾,字符串中有1个或多个点(.) @CheckWith(value=PasswordCheck.class,message=“validation.password.blah.foo”) 下面的正则表达式给出了字符串validation.password.blah的前三个部分,但忽略了.foo (\")([a-zA-Z]{1,}\.{1}){1,} 请尝

下面的字符串可能会在不同的文档中以不同的格式出现任意次数,我想把引号之间的部分去掉。我只想要满足以下条件的字符串。以“(两个引号之间)开头和结尾,字符串中有1个或多个点(.)

@CheckWith(value=PasswordCheck.class,message=“validation.password.blah.foo”)

下面的正则表达式给出了字符串validation.password.blah的前三个部分,但忽略了.foo

(\")([a-zA-Z]{1,}\.{1}){1,}
请尝试以下操作:

"([a-zA-Z]{1,}\.[a-zA-Z.]{1,})"
请注意,您通常可以使用
+
,而不是
{1,}
,但我不确定grep是否在没有扩展选项的情况下支持该选项

说明:

"                  # match a literal '"' character
(                  # start capture group
  [a-zA-Z]{1,}       # one or more letters
  \.                 # match a literal '.' character
  [a-zA-Z.]{1,}      # one or more letters or '.' characters
)                  # end capture group
"                  # match a literal '"' character

我想你要找的正则表达式是:
“[a-zA-Z]+(\[a-zA-Z]+)+


您应该记住,它不会包括最后一个
,只接受点之间的字母。

如果您有
egrep
(或
grep-E
),您可以使用

"([a-zA_Z]+\.)+[a-zA-Z]+"
(引号是正则表达式的一部分,如果需要,可以转义)