简体   繁体   English

正则表达式/ grep从字符串中拉出点路径

[英]Regex/grep to pull dot path out of string

Given the following string which may appear any number of times across various documents and in various different formats, I want to pull out the part between the quotes. 鉴于以下字符串可能会在各种文档中以各种不同的格式出现多次,因此我想引述引号之间的部分。 I Only want strings which meet the following conditions. 我只想要满足以下条件的字符串。 Starts and ends with " (between two quotes) and has 1 or more dots (.) within the string. 以“(在两个引号之间)开头和结尾,并且在字符串中具有1个或多个点(。)。

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

The following regex gives me the first three parts of the string validation.password.blah but misses the .foo 以下正则表达式为我提供了字符串validation.password.blah的前三个部分,但缺少.foo

(\")([a-zA-Z]{1,}\.{1}){1,}

Try the following: 请尝试以下操作:

"([a-zA-Z]{1,}\.[a-zA-Z.]{1,})"

Note that instead of {1,} you can usually use + , but I'm not sure if grep supports that without an extended option. 请注意,通常可以使用+代替{1,} ,但是我不确定grep是否支持不带扩展选项的功能。

Explanation: 说明:

"                  # 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

I think the regex you are looking for is this: "[a-zA-Z]+(\\.[a-zA-Z]+)+ 我认为您要查找的正则表达式是这样的: "[a-zA-Z]+(\\.[a-zA-Z]+)+

You should have in mind that it wont include last " and will only accept letters between the dots. 您应该记住,它不会包含last "并且仅接受点之间的字母。

If you have egrep (or grep -E ), you can use 如果您有egrep (或grep -E ),则可以使用

"([a-zA_Z]+\.)+[a-zA-Z]+"

(quotes are part of the regex, escape if needed). (引号是正则表达式的一部分,如果需要,请转义)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM